Skip to content

Commit

Permalink
Merge pull request #432 from Paraphraser/20211015-telegraf-influx-con…
Browse files Browse the repository at this point in the history
…tainer-experimental

20211015 Telegraf - defaults - experimental branch - PR 3 of 3
  • Loading branch information
Slyke authored Oct 17, 2021
2 parents 3ab3adf + 6b88346 commit ce0b4e2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
20 changes: 17 additions & 3 deletions .internal/templates/services/telegraf/buildFiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ RUN apt update && apt install -y rsync
# where IOTstack template files are stored
ENV IOTSTACK_DEFAULTS_DIR="iotstack_defaults"

# make a copy of the default config file
RUN mkdir -p /${IOTSTACK_DEFAULTS_DIR} && \
cp /etc/telegraf/telegraf.conf /${IOTSTACK_DEFAULTS_DIR}/
# copy template files to image
COPY ${IOTSTACK_DEFAULTS_DIR} /${IOTSTACK_DEFAULTS_DIR}

# 1. copy the default configuration file that ships with the image as
# a baseline reference for the user, and make it read-only.
# 2. strip comment lines and blank lines from the baseline reference to
# use as the starting point for the IOTstack default configuration.
# 3. edit the IOTstack default configuration to insert an appropriate
# URL for influxdb running in another container in the same stack.
ENV BASELINE_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf-reference.conf
ENV IOTSTACK_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf.conf
RUN cp /etc/telegraf/telegraf.conf ${BASELINE_CONFIG} && \
chmod 444 ${BASELINE_CONFIG} && \
grep -v -e "^[ ]*#" -e "^[ ]*$" ${BASELINE_CONFIG} >${IOTSTACK_CONFIG} && \
sed -i '/^\[\[outputs.influxdb\]\]/a\ \ urls = ["http://influxdb:8086"]' ${IOTSTACK_CONFIG}
ENV BASELINE_CONFIG=
ENV IOTSTACK_CONFIG=

# replace the docker entry-point script with a self-repairing version
ENV IOTSTACK_ENTRY_POINT="entrypoint.sh"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Read metrics about docker containers
# Credit: @tablatronix
[[inputs.docker]]
endpoint = "unix:///var/run/docker.sock"
gather_services = false
container_names = []
source_tag = false
container_name_include = []
container_name_exclude = []
timeout = "5s"
perdevice = false
total = true
docker_label_include = []
docker_label_exclude = []
tag_env = ["HEAP_SIZE"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Read metrics from MQTT topic(s)
# Credit: https://github.com/gcgarner/IOTstack/blob/master/.templates/telegraf/telegraf.conf
[[inputs.mqtt_consumer]]
servers = ["tcp://mosquitto:1883"]
topics = [
"telegraf/host01/cpu",
"telegraf/+/mem",
"sensors/#",
]
data_format = "json"
1 change: 1 addition & 0 deletions .internal/templates/services/telegraf/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ telegraf:
- "8125:8125/udp"
volumes:
- ./volumes/telegraf/:/etc/telegraf
- /var/run/docker.sock:/var/run/docker.sock:ro
depends_on:
- influxdb
- mosquitto
Expand Down

0 comments on commit ce0b4e2

Please sign in to comment.