Skip to content

Commit ee15e2a

Browse files
committed
20211005 Prometheus revamp - old-menu branch - PR 2 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`, `service_node-exporter.yml` and the empty `prometheus.env` from the template as no longer necessary.
1 parent 46bbde9 commit ee15e2a

File tree

9 files changed

+103
-70
lines changed

9 files changed

+103
-70
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 & 32 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/prometheus.env

Whitespace-only changes.

.templates/prometheus/service.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
prometheus:
22
container_name: prometheus
3-
image: prom/prometheus:latest
3+
build: ./.templates/prometheus/.
44
restart: unless-stopped
55
user: "0"
66
ports:
7-
- 9090:9090
8-
env_file:
9-
- ./services/prometheus/prometheus.env
10-
depends_on:
7+
- "9090:9090"
8+
environment:
9+
- IOTSTACK_UID=1000
10+
- IOTSTACK_GID=1000
1111
volumes:
12-
- ./services/prometheus/config.yml:/etc/prometheus/config.yml
13-
- ./volumes/prometheus/data:/data
12+
- ./volumes/prometheus/data:/prometheus
1413
command:
15-
- '--config.file=/etc/prometheus/config.yml'
16-
- '--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
1723

24+
cadvisor:
25+
container_name: cadvisor
26+
image: zcube/cadvisor:latest
27+
restart: unless-stopped
28+
ports:
29+
- "8082:8080"
30+
volumes:
31+
- /:/rootfs:ro
32+
- /var/run:/var/run:rw
33+
- /sys:/sys:ro
34+
- /var/lib/docker/:/var/lib/docker:ro
35+
36+
nodeexporter:
37+
container_name: nodeexporter
38+
image: prom/node-exporter:latest
39+
restart: unless-stopped
40+
expose:
41+
- "9100"

.templates/prometheus/service_cadvisor-arm.yml

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

.templates/prometheus/service_node-exporter.yml

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

0 commit comments

Comments
 (0)