Skip to content

Commit 3bbbd60

Browse files
authored
Merge pull request #431 from Paraphraser/20211015-telegraf-influx-container-old-menu
20211015 Telegraf - defaults - old-menu branch - PR 2 of 3
2 parents 46bbde9 + f7e07bc commit 3bbbd60

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

.templates/telegraf/Dockerfile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@ RUN apt update && apt install -y rsync
77
# where IOTstack template files are stored
88
ENV IOTSTACK_DEFAULTS_DIR="iotstack_defaults"
99

10-
# make a copy of the default config file
11-
RUN mkdir -p /${IOTSTACK_DEFAULTS_DIR} && \
12-
cp /etc/telegraf/telegraf.conf /${IOTSTACK_DEFAULTS_DIR}/
10+
# copy template files to image
11+
COPY ${IOTSTACK_DEFAULTS_DIR} /${IOTSTACK_DEFAULTS_DIR}
12+
13+
# 1. copy the default configuration file that ships with the image as
14+
# a baseline reference for the user, and make it read-only.
15+
# 2. strip comment lines and blank lines from the baseline reference to
16+
# use as the starting point for the IOTstack default configuration.
17+
# 3. edit the IOTstack default configuration to insert an appropriate
18+
# URL for influxdb running in another container in the same stack.
19+
ENV BASELINE_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf-reference.conf
20+
ENV IOTSTACK_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf.conf
21+
RUN cp /etc/telegraf/telegraf.conf ${BASELINE_CONFIG} && \
22+
chmod 444 ${BASELINE_CONFIG} && \
23+
grep -v -e "^[ ]*#" -e "^[ ]*$" ${BASELINE_CONFIG} >${IOTSTACK_CONFIG} && \
24+
sed -i '/^\[\[outputs.influxdb\]\]/a\ \ urls = ["http://influxdb:8086"]' ${IOTSTACK_CONFIG}
25+
ENV BASELINE_CONFIG=
26+
ENV IOTSTACK_CONFIG=
1327

1428
# replace the docker entry-point script with a self-repairing version
1529
ENV IOTSTACK_ENTRY_POINT="entrypoint.sh"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Read metrics about docker containers
2+
# Credit: @tablatronix
3+
[[inputs.docker]]
4+
endpoint = "unix:///var/run/docker.sock"
5+
gather_services = false
6+
container_names = []
7+
source_tag = false
8+
container_name_include = []
9+
container_name_exclude = []
10+
timeout = "5s"
11+
perdevice = false
12+
total = true
13+
docker_label_include = []
14+
docker_label_exclude = []
15+
tag_env = ["HEAP_SIZE"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Read metrics from MQTT topic(s)
2+
# Credit: https://github.com/gcgarner/IOTstack/blob/master/.templates/telegraf/telegraf.conf
3+
[[inputs.mqtt_consumer]]
4+
servers = ["tcp://mosquitto:1883"]
5+
topics = [
6+
"telegraf/host01/cpu",
7+
"telegraf/+/mem",
8+
"sensors/#",
9+
]
10+
data_format = "json"

.templates/telegraf/service.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- "8125:8125/udp"
1111
volumes:
1212
- ./volumes/telegraf/:/etc/telegraf
13+
- /var/run/docker.sock:/var/run/docker.sock:ro
1314
depends_on:
1415
- influxdb
1516
- mosquitto

0 commit comments

Comments
 (0)