-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathenvironment.sh
executable file
·74 lines (59 loc) · 2.09 KB
/
environment.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
#!/usr/bin/env sh
PROMETHEUS_NAME="prometheus"
: "${PROMETHEUS_IMAGE:="docker.io/prom/prometheus:latest"}"
PROMETHEUS_NAME_PROXY="prometheus_proxy"
PROMETHEUS_PORT=9090
RUNTIME="docker"
OPTS=""
if command -v podman &> /dev/null
then
RUNTIME=podman
OPTS="--security-opt label=disable"
fi
if ! command -v $RUNTIME &> /dev/null
then
echo "neither podman nor docker were found, aborting"
exit 1
fi
echo "detected runtime is $RUNTIME, starting containers. this can take some time..."
# Create a basic prometheus config file
cat > prometheus.yml <<- EOF
global:
scrape_interval: 10s
evaluation_interval: 30s
remote_write:
- name: proxy
url: http://localhost:8080
oauth2:
client_id: <client_id>
client_secret: <client_secret>
token_url: <token_url>
EOF
# Create a basic prometheus config file for the proxy target
cat > prometheusProxy.yml <<- EOF
global:
scrape_interval: 10s
evaluation_interval: 30s
EOF
# start the prometheus container
echo "starting prometheus container from image $PROMETHEUS_IMAGE"
$RUNTIME run -d --rm --name $PROMETHEUS_NAME --network=host $OPTS -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml $PROMETHEUS_IMAGE --web.enable-remote-write-receiver --config.file=/etc/prometheus/prometheus.yml
PROMETHEUS_CONTAINER=`$RUNTIME ps -f name=$PROMETHEUS_NAME --format "{{.ID}}"`
$RUNTIME run -d --rm --name $PROMETHEUS_NAME_PROXY --network=host $OPTS -v $(pwd)/prometheusProxy.yml:/etc/prometheus/prometheus.yml $PROMETHEUS_IMAGE --web.enable-remote-write-receiver --config.file=/etc/prometheus/prometheus.yml
PROMETHEUS_CONTAINER_PROXY=`$RUNTIME ps -f name=$PROMETHEUS_NAME_PROXY--format "{{.ID}}"`
cleanup() {
echo "stopping prometheus container $PROMETHEUS_CONTAINER"
$RUNTIME stop "$PROMETHEUS_CONTAINER" &> /dev/null
rm -f prometheus.yml
echo "stopping prometheus container $PROMETHEUS_CONTAINER_PROXY"
$RUNTIME stop "$PROMETHEUS_CONTAINER_PROXY" &> /dev/null
rm -f prometheusProxy.yml
echo "done"
exit 0
}
trap 'cleanup' SIGINT
echo "Prometheus is running on port $PROMETHEUS_PORT"
echo "press ctrl-c to quit"
while true; do
sleep 1
done