-
Notifications
You must be signed in to change notification settings - Fork 6
/
PF_StartupScript.sh
26 lines (18 loc) · 1.04 KB
/
PF_StartupScript.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
set -o errexit # script exits when a command fails == set -e
set -o nounset # script exits when tries to use undeclared variables == set -u
set -o xtrace # trace what's executed == set -x (useful for debugging)
set -o pipefail # causes pipelines to retain / set the last non-zero status
# get script's path
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# install telegraf
sudo apt-get -yq --no-install-recommends install "${DIR}"/telegraf.deb
systemctl stop telegraf
# remove \r\n in-place
sed -i -e 's/\r$//' ${DIR}/telegraf.conf
mkdir -p /etc/telegraf || echo 'Warning: /etc/telegraf already exists'
# add PF_TITLE_ID, PF_BUILD_ID, PF_VM_ID to telegraf.conf as dimensions
sed -e "s/_%PF_TITLE_ID%_/${PF_TITLE_ID}/g" -e "s/_%PF_BUILD_ID%_/${PF_BUILD_ID}/g" -e "s/_%PF_VM_ID%_/${PF_VM_ID}/g" -e "s/_%PF_REGION%_/${PF_REGION}/g" ${DIR}/telegraf.conf > /etc/telegraf/telegraf.conf
# add user telegraf to group docker so telegraf daemon can read docker logs
sudo usermod -a -G docker telegraf
systemctl restart telegraf