forked from scylladb/scylla-monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprometheus-config.sh
More file actions
executable file
·196 lines (187 loc) · 5.3 KB
/
Copy pathprometheus-config.sh
File metadata and controls
executable file
·196 lines (187 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
usage="$(basename "$0") [-h] [-m alert_manager address] [-L] [-T additional-prometheus-targets] [-G grafana address] [--compose] -- Generate grafana's datasource file"
CONSUL_ADDRESS=""
COMPOSE=0
BASE_DIR="$PWD/prometheus/build"
if [ -f env.sh ]; then
. env.sh
fi
if [ "$1" = "" ]; then
echo "$usage"
exit
fi
for arg; do
shift
if [ -z "$PARAM" ]; then
case $arg in
--compose)
COMPOSE=1
AM_ADDRESS="aalert:9093"
;;
--no-cas-cdc)
NO_CAS="1"
NO_CDC="1"
;;
--no-cas)
NO_CAS="1"
;;
--no-cdc)
NO_CDC="1"
;;
--scrap)
PARAM="scrap"
;;
--vector-store)
VECTOR_SEARCH="1"
;;
--vector-search)
VECTOR_SEARCH="1"
;;
--native-histogram)
NATIVE_HISTOGRAM="1"
;;
--no-node-exporter-file)
NO_NODE_EXPORTER_FILE="1"
;;
--no-manager-agent-file)
NO_MANAGER_AGENT_FILE="1"
;;
*)
set -- "$@" "$arg"
;;
esac
else
DOCR=$(echo $arg | cut -d',' -f1)
VALUE=$(echo $arg | cut -d',' -f2- | sed 's/#/ /g')
NOSPACE=$(echo $arg | sed 's/ /#/g')
if [[ $NOSPACE == --* ]]; then
echo "Error: No value given to --$PARAM"
echo
usage
exit 1
fi
if [ "$PARAM" = "scrap" ]; then
SCRAP_INTERVAL="$NOSPACE"
fi
unset PARAM
fi
done
while getopts ':hL:m:T:E:G:s:' option; do
case "$option" in
h)
echo "$usage"
exit
;;
L)
CONSUL_ADDRESS="$OPTARG"
;;
T)
PROMETHEUS_TARGETS+=("$OPTARG")
;;
m)
AM_ADDRESS="$OPTARG"
;;
s)
BASE_DIR="$PWD/prometheus/build/stack/$OPTARG"
;;
E)
EVALUATION_INTERVAL="$OPTARG"
;;
G) GRAFANA_ADDRESS="$OPTARG"
;;
:)
printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?)
printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
if [ "$GRAFANA_ADDRESS" = "" ]; then
GRAFANA_ADDRESS="agraf:3000"
fi
mkdir -p $BASE_DIR/
if [ -z $CONSUL_ADDRESS ]; then
sed "s/AM_ADDRESS/$AM_ADDRESS/" $PWD/prometheus/prometheus.yml.template| sed "s/GRAFANA_ADDRESS/$GRAFANA_ADDRESS/" >$BASE_DIR/prometheus.yml
else
if [[ ! $CONSUL_ADDRESS = *":"* ]]; then
CONSUL_ADDRESS="$CONSUL_ADDRESS:5090"
fi
sed "s/AM_ADDRESS/$AM_ADDRESS/" $PWD/prometheus/prometheus.consul.yml.template | sed "s/MANAGER_ADDRESS/$CONSUL_ADDRESS/" | sed "s/GRAFANA_ADDRESS/$GRAFANA_ADDRESS/" >$BASE_DIR/prometheus.yml
fi
if [[ "$EVALUATION_INTERVAL" != "" ]]; then
sed -i "s/ evaluation_interval: [[:digit:]]*.*/ evaluation_interval: ${EVALUATION_INTERVAL}/g" $BASE_DIR/prometheus.yml
fi
if [ "$NATIVE_HISTOGRAM" = "1" ]; then
sed -i "s/ scrape_native_histograms:.*/ scrape_native_histograms: true/g" $BASE_DIR/prometheus.yml
fi
if [[ "$SCRAP_INTERVAL" != "" ]]; then
sed -i "s/ scrape_interval: [[:digit:]]*.*# *Default.*/ scrape_interval: ${SCRAP_INTERVAL}s/g" $BASE_DIR/prometheus.yml
TIMEOUT=$(($SCRAP_INTERVAL - 5))
sed -i "s/ scrape_timeout: [[:digit:]]*.*# *Default.*/ scrape_timeout: ${TIMEOUT}s/g" $BASE_DIR/prometheus.yml
fi
if [ "$NO_CAS" = "1" ] && [ "$NO_CDC" = "1" ]; then
sed -i "s/ *# FILTER_METRICS.*/ - source_labels: [__name__]\\n regex: '(.*_cdc_.*|.*_cas.*)'\\n action: drop/g" $BASE_DIR/prometheus.yml
elif [ "$NO_CAS" = "1" ]; then
sed -i "s/ *# FILTER_METRICS.*/ - source_labels: [__name__]\\n regex: '(.*_cas.*)'\\n action: drop/g" $BASE_DIR/prometheus.yml
elif [ "$NO_CDC" = "1" ]; then
sed -i "s/ *# FILTER_METRICS.*/ - source_labels: [__name__]\\n regex: '(.*_cdc_.*)'\\n action: drop/g" $BASE_DIR/prometheus.yml
fi
if [ "$NO_NODE_EXPORTER_FILE" = "1" ]; then
sed -i "s/ *# NODE_EXPORTER_PORT_MAPPING.*/ - source_labels: [__address__]\\n regex: '(.*):\\\\d+'\\n target_label: __address__\\n replacement: '\$\{1\}'\\n/g" $BASE_DIR/prometheus.yml
fi
if [ "$NO_MANAGER_AGENT_FILE" = "1" ]; then
sed -i "s/ *# MANAGER_AGENT_PORT_MAPPING.*/ - source_labels: [__address__]\\n regex: '(.*):\\\\d+'\\n target_label: __address__\\n replacement: \'\$\{1\}\'\\n/g" $BASE_DIR/prometheus.yml
fi
for val in "${PROMETHEUS_TARGETS[@]}"; do
if [[ ! -f $val ]]; then
echo "Target file $val does not exists"
exit 1
fi
cat $val >>$BASE_DIR/prometheus.yml
done
if [ ! -z "$VECTOR_SEARCH" ]; then
__target="- job_name: vector_search
honor_labels: false
file_sd_configs:
- files:
- /etc/scylla.d/prometheus/targets/vector_search_servers.yml
relabel_configs:
- source_labels: [__address__, __port__]
regex: '(.+);$'
target_label: __address__
replacement: '\${1}:6080'
- source_labels: [instance, __address__]
regex: ';(.+):.+'
action: replace
target_label: instance
replacement: '\${1}'
- source_labels: [keyspace, index_name]
separator: ','
target_label: ks_index
- job_name: vector_search_os
honor_labels: false
file_sd_configs:
- files:
- /etc/scylla.d/prometheus/targets/vector_search_servers.yml
relabel_configs:
- source_labels: [__address__]
regex: '(.+)[:]\d+$'
target_label: __address__
replacement: '\${1}'
- source_labels: [__address__]
regex: '(.+)'
target_label: __address__
replacement: '\${1}:9100'
- source_labels: [instance, __address__]
regex: ';(.+):.+'
action: replace
target_label: instance
replacement: '\${1}'
"
echo "$__target" >>$BASE_DIR/prometheus.yml
fi