Skip to content

Commit 12a68ff

Browse files
committed
20211005 Prometheus revamp - master branch - PR 1 of 3
A [Discord thread](https://discord.com/channels/638610460567928832/638610461109256194/891417109920362518) revealed several problems with Prometheus including: * `build.sh` not being run * `config.yml` not being in the right place * `config.yml` scraping not being adjusted if CAdvisor and Node Exporter were selected in the menu. This Pull Request proposes a revamp of Prometheus: 1. A single service definition which includes Prometheus, CAdvisor and Node Exporter. Note that this changes the `prometheus` fragment from the previous pairing of: ``` volumes: - ./volumes/prometheus/data:/data command: - '--storage.tsdb.path=/data' ``` to: ``` volumes: - ./volumes/prometheus/data:/prometheus ``` which is the default for the `--storage` argument. 2. A matching `config.yml` set to scrape information from all three cooperating containers. The file is referenced as: ``` command: - '--config.file=/prometheus/config/config.yml' ``` so it automatically becomes part of the persistent storage area. 3. Self-healing functionality similar to the Mosquitto example implemented via a Dockerfile. Removes `build.sh`, `service_cadvisor-arm.yml` and `service_node-exporter.yml` from the template as no longer necessary. Adds container documentation for Prometheus (previously non-existent).
1 parent 651a30b commit 12a68ff

File tree

9 files changed

+462
-74
lines changed

9 files changed

+462
-74
lines changed

.templates/prometheus/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Download base image
2+
FROM prom/prometheus:latest
3+
4+
USER root
5+
6+
# where IOTstack template files are stored
7+
ENV IOTSTACK_DEFAULTS_DIR="iotstack_defaults"
8+
ENV IOTSTACK_CONFIG_DIR="/prometheus/config/"
9+
10+
# copy template files to image
11+
COPY --chown=nobody:nobody ${IOTSTACK_DEFAULTS_DIR} /${IOTSTACK_DEFAULTS_DIR}
12+
13+
# add default config from image to template
14+
RUN cp /etc/prometheus/prometheus.yml /${IOTSTACK_DEFAULTS_DIR}
15+
16+
# replace the docker entry-point script
17+
ENV IOTSTACK_ENTRY_POINT="docker-entrypoint.sh"
18+
COPY ${IOTSTACK_ENTRY_POINT} /${IOTSTACK_ENTRY_POINT}
19+
RUN chmod 755 /${IOTSTACK_ENTRY_POINT}
20+
ENTRYPOINT ["/docker-entrypoint.sh"]
21+
ENV IOTSTACK_ENTRY_POINT=
22+
23+
USER nobody
24+
25+
# EOF

.templates/prometheus/build.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

.templates/prometheus/config.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/ash
2+
set -e
3+
4+
# set defaults for config structure ownership
5+
UID="${IOTSTACK_UID:-nobody}"
6+
GID="${IOTSTACK_GID:-nobody}"
7+
8+
# were we launched as root?
9+
if [ "$(id -u)" = "0" -a -d /"$IOTSTACK_DEFAULTS_DIR" ]; then
10+
11+
# yes! ensure that the IOTSTACK_CONFIG_DIR exists
12+
mkdir -p "$IOTSTACK_CONFIG_DIR"
13+
14+
# populate runtime directory from the defaults
15+
for P in /"$IOTSTACK_DEFAULTS_DIR"/* ; do
16+
17+
C=$(basename "$P")
18+
19+
if [ ! -e "$IOTSTACK_CONFIG_DIR/$C" ] ; then
20+
21+
cp -a "$P" "$IOTSTACK_CONFIG_DIR/$C"
22+
23+
fi
24+
25+
done
26+
27+
# enforce correct ownership
28+
chown -R "$UID":"$GID" "$IOTSTACK_CONFIG_DIR"
29+
30+
fi
31+
32+
# launch prometheus with supplied arguments
33+
exec /bin/prometheus "$@"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
global:
2+
scrape_interval: 10s
3+
evaluation_interval: 10s
4+
5+
scrape_configs:
6+
- job_name: "iotstack"
7+
static_configs:
8+
- targets:
9+
- localhost:9090
10+
- cadvisor:8080
11+
- nodeexporter:9100
12+

.templates/prometheus/service.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
11
prometheus:
22
container_name: prometheus
3-
image: prom/prometheus:latest
3+
build: ./.templates/prometheus/.
44
restart: unless-stopped
55
user: "0"
66
ports:
77
- "9090:9090"
8+
environment:
9+
- IOTSTACK_UID=1000
10+
- IOTSTACK_GID=1000
811
volumes:
9-
- ./services/prometheus/config.yml:/etc/prometheus/config.yml
10-
- ./volumes/prometheus/data:/data
12+
- ./volumes/prometheus/data:/prometheus
1113
command:
12-
- '--config.file=/etc/prometheus/config.yml'
13-
- '--storage.tsdb.path=/data'
14+
- '--config.file=/prometheus/config/config.yml'
15+
# defaults are:
16+
# - --config.file=/etc/prometheus/prometheus.yml
17+
# - --storage.tsdb.path=/prometheus
18+
# - --web.console.libraries=/usr/share/prometheus/console_libraries
19+
# - --web.console.templates=/usr/share/prometheus/consoles
20+
depends_on:
21+
- cadvisor
22+
- nodeexporter
23+
networks:
24+
- iotstack_nw
25+
26+
cadvisor:
27+
container_name: cadvisor
28+
image: zcube/cadvisor:latest
29+
restart: unless-stopped
30+
ports:
31+
- "8082:8080"
32+
volumes:
33+
- /:/rootfs:ro
34+
- /var/run:/var/run:rw
35+
- /sys:/sys:ro
36+
- /var/lib/docker/:/var/lib/docker:ro
37+
networks:
38+
- iotstack_nw
39+
40+
nodeexporter:
41+
container_name: nodeexporter
42+
image: prom/node-exporter:latest
43+
restart: unless-stopped
44+
expose:
45+
- "9100"
1446
networks:
1547
- iotstack_nw

.templates/prometheus/service_cadvisor-arm.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.templates/prometheus/service_node-exporter.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)