From 3b0e3ff8cfbeea706e7f93c4f0aef83ee14c3179 Mon Sep 17 00:00:00 2001 From: 11notes Date: Tue, 18 Oct 2022 14:43:49 +0200 Subject: [PATCH] first commit --- .gitignore | 1 + README.md | 41 ++++++++++++++++++++++++++ amd64.dockerfile | 46 ++++++++++++++++++++++++++++++ rootfs/telegraf/etc/telegraf.conf | 25 ++++++++++++++++ rootfs/usr/local/bin/entrypoint.sh | 7 +++++ 5 files changed, 120 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 amd64.dockerfile create mode 100644 rootfs/telegraf/etc/telegraf.conf create mode 100644 rootfs/usr/local/bin/entrypoint.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3cdab39 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +maintain/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..fcb922d --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# Info +The plugin-driven server agent for collecting & reporting metrics. + +This container provides an easy and simple way to use telegraf without the hassle of library dependencies and compiling the source yourself. + +## Volumes +None + +## Run +```shell +docker run --name telegraf \ +  -v /.../telegraf.conf:/telegraf/etc/telegraf.conf:ro \ +  -d 11notes/telegraf:[tag] +``` + +# Examples telegraf.conf +```shell +[agent] + interval = "10s" + round_interval = true + metric_batch_size = 1000 + metric_buffer_limit = 10000 + collection_jitter = "0s" + flush_interval = "10s" + flush_jitter = "0s" + precision = "0s" + hostname = "telegraf" + +[[outputs.influxdb_v2]] + urls = ["http://localhost:8086"] + token = "**********************************************" + organization = "influxdb" + bucket = "global" + +[[inputs.prometheus]] + urls = ["http://localhost:8080/metrics"] +``` + +## Build with +* [telegraf](https://github.com/influxdata/telegraf) - Telegraf +* [Alpine Linux](https://alpinelinux.org/) - Alpine Linux \ No newline at end of file diff --git a/amd64.dockerfile b/amd64.dockerfile new file mode 100644 index 0000000..a5a952f --- /dev/null +++ b/amd64.dockerfile @@ -0,0 +1,46 @@ +# :: Build + FROM golang:alpine as telegraf + ENV checkout=v1.24.2 + + RUN set -ex; \ + apk add --update --no-cache \ + make \ + git; \ + git clone https://github.com/influxdata/telegraf.git; \ + cd /go/telegraf; \ + git checkout ${checkout}; \ + make build -j $(nproc); \ + mv telegraf /usr/local/bin; + +# :: Header + FROM alpine:3.16 + COPY --from=telegraf /usr/local/bin/ /usr/local/bin + +# :: Run + USER root + + # :: prepare + RUN set -ex; \ + mkdir -p /telegraf; \ + mkdir -p /telegraf/etc; + + RUN set -ex; \ + apk add --update --no-cache \ + shadow; + + RUN set -ex; \ + addgroup --gid 1000 -S telegraf; \ + adduser --uid 1000 -D -S -h /telegraf -s /sbin/nologin -G telegraf telegraf; + + # :: copy root filesystem changes + COPY ./rootfs / + + # :: docker -u 1000:1000 (no root initiative) + RUN set -ex; \ + chown -R telegraf:telegraf \ + /telegraf + +# :: Start + RUN set -ex; chmod +x /usr/local/bin/entrypoint.sh + USER telegraf + ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] \ No newline at end of file diff --git a/rootfs/telegraf/etc/telegraf.conf b/rootfs/telegraf/etc/telegraf.conf new file mode 100644 index 0000000..27b7c37 --- /dev/null +++ b/rootfs/telegraf/etc/telegraf.conf @@ -0,0 +1,25 @@ +[agent] + interval = "10s" + round_interval = true + metric_batch_size = 1000 + metric_buffer_limit = 10000 + collection_jitter = "0s" + flush_interval = "10s" + flush_jitter = "0s" + precision = "0s" + hostname = "telegraf" + +############################################################################### +# OUTPUT PLUGINS # +############################################################################### +[[outputs.influxdb_v2]] + urls = ["http://localhost:8086"] + token = "**********************************************" + organization = "influxdb" + bucket = "global" + +############################################################################### +# INPUT PLUGINS # +############################################################################### +[[inputs.prometheus]] + urls = ["http://localhost:8080/metrics"] \ No newline at end of file diff --git a/rootfs/usr/local/bin/entrypoint.sh b/rootfs/usr/local/bin/entrypoint.sh new file mode 100644 index 0000000..135e339 --- /dev/null +++ b/rootfs/usr/local/bin/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/ash +if [ -z "${1}" ]; then + set -- "telegraf" \ + --config /telegraf/etc/telegraf.conf +fi + +exec "$@" \ No newline at end of file