forked from scylladb/scylla-monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-thanos.sh
executable file
·137 lines (128 loc) · 3.58 KB
/
start-thanos.sh
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
#!/usr/bin/env bash
. versions.sh
if [ -f env.sh ]; then
. env.sh
fi
function usage {
__usage="Usage: $(basename $0) [-h] [-S ip:port]
Options:
-h print this help and exit
-S sidecart address - A side cart address:port multiple side cart can be comma delimited
The script starts Thanos query, it connect to external Thanos side carts and act as a grafana data source
"
echo "$__usage"
}
function update_data_source {
THANOS_ADDRESS="$(docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' thanos)"
if [[ $THANOS_ADDRESS = "" ]]; then
THANOS_ADDRESS=`hostname -I | awk '{print $1}'`
fi
THANOS_ADDRESS="$THANOS_ADDRESS:10904"
__datasource="# config file version
apiVersion: 1
datasources:
- name: thanos
type: prometheus
url: http://$THANOS_ADDRESS
access: proxy
basicAuth: false
"
echo "$__datasource" > grafana/provisioning/datasources/thanos.yaml
}
LIMITS=""
VOLUMES=""
PARAMS=""
for arg; do
shift
if [ -z "$LIMIT" ]; then
case $arg in
(--limit)
LIMIT="1"
;;
(--volume)
LIMIT="1"
VOLUME="1"
;;
(--param)
LIMIT="1"
PARAM="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 [ "$PARAM" = "1" ]; then
if [ -z "${DOCKER_PARAMS[$DOCR]}" ]; then
DOCKER_PARAMS[$DOCR]=""
fi
DOCKER_PARAMS[$DOCR]="${DOCKER_PARAMS[$DOCR]} $VALUE"
PARAMS="$PARAMS --param $NOSPACE"
unset PARAM
else
if [ -z "${DOCKER_LIMITS[$DOCR]}" ]; then
DOCKER_LIMITS[$DOCR]=""
fi
if [ "$VOLUME" = "1" ]; then
SRC=`echo $VALUE|cut -d':' -f1`
DST=`echo $VALUE|cut -d':' -f2-`
SRC=$(readlink -m $SRC)
DOCKER_LIMITS[$DOCR]="${DOCKER_LIMITS[$DOCR]} -v $SRC:$DST"
VOLUMES="$VOLUMES --volume $NOSPACE"
unset VOLUME
else
DOCKER_LIMITS[$DOCR]="${DOCKER_LIMITS[$DOCR]} $VALUE"
LIMITS="$LIMITS --limit $NOSPACE"
fi
fi
unset LIMIT
fi
done
SIDECAR=()
if [ "$DOCKER_PARAM" != "" ]; then
DOCKER_PARAM_FROM_FILE="1"
else
DOCKER_PARAM=""
fi
while getopts ':hlp:S:D:' option; do
case "$option" in
l) if [[ "$DOCKER_PARAM" != *"--net=host"* ]]; then
DOCKER_PARAM="$DOCKER_PARAM --net=host"
fi
;;
h) usage
exit
;;
S) IFS=',' ;for s in $OPTARG; do
SIDECAR+=(--store=$s)
done
;;
D) if [ "$DOCKER_PARAM_FROM_FILE" = "1" ]; then
DOCKER_PARAM=""
DOCKER_PARAM_FROM_FILE=""
fi
DOCKER_PARAM="$DOCKER_PARAM $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
docker run ${DOCKER_LIMITS["thanos"]} -d $DOCKER_PARAM -i --name thanos -- docker.io/thanosio/thanos:$THANOS_VERSION \
query \
"--debug.name=query0" \
"--grpc-address=0.0.0.0:10903" \
"--grpc-grace-period=1s" \
"--http-address=0.0.0.0:10904" \
"--http-grace-period=1s" \
"--query.replica-label=prometheus" \
${DOCKER_PARAMS["thanos"]} \
${SIDECAR[@]}
update_data_source