Skip to content

Commit b725d2b

Browse files
author
Jonathan Chauncey
committed
Merge pull request #79 from sstarcher/master
feat: global tags, upgrade to influxdb, upgrade to telegraph
2 parents 3a8deb4 + 993893a commit b725d2b

4 files changed

Lines changed: 37 additions & 22 deletions

File tree

telegraf/rootfs/Dockerfile

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
FROM alpine:3.2
1+
FROM alpine:3.3
22
MAINTAINER Jonathan Chauncey "<jchauncey@deis.com>"
33

4-
ENV TELEGRAF_VERSION "0.10.0_linux_amd64"
4+
ENV TELEGRAF_VERSION=0.12.0
5+
RUN \
6+
mkdir -p /usr/local/bin/ &&\
7+
apk --update add curl &&\
8+
curl -SL http://get.influxdb.org/telegraf/telegraf-${TELEGRAF_VERSION}-1_linux_amd64.tar.gz \
9+
| tar xzC / &&\
10+
apk del --purge curl && \
11+
rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
12+
# Alpine telegraf fix
13+
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
514

6-
RUN apk --update add bash curl
715

8-
# The download links for the zip of telegraf are broken.
9-
# So for now Im building this locally and copying it into the build context.
10-
ADD https://bintray.com/artifact/download/jchauncey/telegraf/telegraf/telegraf /telegraf
11-
ADD https://github.com/arschles/envtpl/releases/download/0.1.2/envtpl_linux_amd64 /envtpl
16+
ENV ENVTPL_VERSION=0.1.2
17+
ADD https://github.com/arschles/envtpl/releases/download/${ENVTPL_VERSION}/envtpl_linux_amd64 /usr/bin/envtpl
18+
RUN chmod +x /usr/bin/envtpl
1219

1320
COPY start-telegraf /start-telegraf
1421
COPY config.toml.tpl /config.toml.tpl
1522

16-
RUN chmod +x /telegraf
17-
RUN chmod +x /envtpl
18-
RUN chmod +x /start-telegraf
19-
2023
ENTRYPOINT ["/start-telegraf"]

telegraf/rootfs/config.toml

Whitespace-only changes.

telegraf/rootfs/config.toml.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Set Tag Configuration
22
[tags]
33

4+
{{ if .GLOBAL_TAGS }}
5+
[global_tags]
6+
{{ range $index, $item := split "," .GLOBAL_TAGS }}
7+
{{ $value := split ":" $item }}{{ $value._0 }}={{ $value._1 | quote }}
8+
{{end}}
9+
{{ end }}
10+
411
# Set Agent Configuration
512
[agent]
613
interval = {{ default "10s" .AGENT_INTERVAL | quote }}

telegraf/rootfs/start-telegraf

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
#!/bin/bash
1+
#!/bin/sh
2+
set -e
3+
24
export PROMETHEUS_BEARER_TOKEN=/var/run/secrets/kubernetes.io/serviceaccount/token
3-
export TOKEN=$(cat $PROMETHEUS_BEARER_TOKEN)
4-
export POD_API_URL=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/api/v1/namespaces/$POD_NAMESPACE/pods/$HOSTNAME
5-
export NODE_NAME=$(curl -s $POD_API_URL --header "Authorization: Bearer $TOKEN" --insecure | grep nodeName | cut -c 18- | tr -d '"')
6-
export AGENT_HOSTNAME=$NODE_NAME
7-
echo "Setting Agent Hostname to: $AGENT_HOSTNAME"
8-
export PROMETHEUS_URLS="\"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/api/v1/proxy/nodes/$NODE_NAME/metrics\", \"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/metrics\""
9-
echo "Setting PROMETHEUS_URLS to: $PROMETHEUS_URLS"
5+
if [ -f $PROMETHEUS_BEARER_TOKEN ]; then
6+
export TOKEN=$(cat $PROMETHEUS_BEARER_TOKEN)
7+
export POD_API_URL=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/api/v1/namespaces/$POD_NAMESPACE/pods/$HOSTNAME
8+
export NODE_NAME=$(curl -s $POD_API_URL --header "Authorization: Bearer $TOKEN" --insecure | grep nodeName | cut -c 18- | tr -d '"')
9+
export AGENT_HOSTNAME=$NODE_NAME
10+
echo "Setting Agent Hostname to: $AGENT_HOSTNAME"
11+
export PROMETHEUS_URLS="\"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/api/v1/proxy/nodes/$NODE_NAME/metrics\", \"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/metrics\""
12+
echo "Setting PROMETHEUS_URLS to: $PROMETHEUS_URLS"
13+
fi
1014

1115
echo "Building config.toml!"
12-
./envtpl -in config.toml.tpl >> config.toml
16+
envtpl -in config.toml.tpl | sed '/^$/d' > config.toml
17+
1318
echo "Finished building toml..."
1419
echo "###########################################"
1520
echo "###########################################"
16-
cat config.toml
21+
cat config.toml
1722
echo "###########################################"
1823
echo "###########################################"
19-
exec /telegraf -config config.toml
24+
telegraf -config config.toml -quiet

0 commit comments

Comments
 (0)