-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart-telegraf
More file actions
executable file
·51 lines (43 loc) · 2.07 KB
/
start-telegraf
File metadata and controls
executable file
·51 lines (43 loc) · 2.07 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -e
API_URL=${API_URL:-"https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT"}
export BEARER_TOKEN_PATH TOKEN NODE_NAME NODE_IP AGENT_HOSTNAME
BEARER_TOKEN_PATH=/var/run/secrets/kubernetes.io/serviceaccount/token
TOKEN="$(cat $BEARER_TOKEN_PATH)"
NODE_NAME="$(curl -s "$API_URL/api/v1/namespaces/$POD_NAMESPACE/pods/$HOSTNAME" --header "Authorization: Bearer $TOKEN" --insecure | jq -r '.spec.nodeName')"
echo "Node Name set (${NODE_NAME})"
NODE_IP="$(curl -s "$API_URL/api/v1/namespaces/$POD_NAMESPACE/pods/$HOSTNAME" --header "Authorization: Bearer $TOKEN" --insecure | jq -r '.status.hostIP')"
echo "Node IP set (${NODE_IP})"
AGENT_HOSTNAME=$NODE_NAME
export NSQ_ENDPOINTS
for NSQ_ENDPOINT in $(echo "$NSQ_ENDPOINTS" |jq '.[]'); do
NSQ_ENDPOINT=${NSQ_ENDPOINT%*\"} # Remove closing quotation mark
NSQ_ENDPOINT=${NSQ_ENDPOINT#*\"} # Remove opening quotation mark
NSQ_TOPIC_URL="$NSQ_ENDPOINT/topic/create?topic=$NSQ_CONSUMER_TOPIC"
echo "Creating topic with URL: ${NSQ_TOPIC_URL}"
curl -s -X POST "${NSQ_TOPIC_URL}"
done
if [ -n "$ENABLE_KUBERNETES" ]; then
export KUBERNETES_BEARER_TOKEN_PATH=${BEARER_TOKEN_PATH}
export KUBERNETES_URL="https://${NODE_IP}:10250"
echo "Setting KUBERNETES_URL: $KUBERNETES_URL"
fi
if [ -n "$ENABLE_PROMETHEUS" ]; then
export PROMETHEUS_BEARER_TOKEN_PATH=${BEARER_TOKEN_PATH}
export PROMETHEUS_URLS="\"$API_URL/api/v1/proxy/nodes/$NODE_NAME/metrics\", \"$API_URL/metrics\""
echo "Setting PROMETHEUS_URLS: $PROMETHEUS_URLS"
fi
# if the influxdb url does not start with a quote, assume it's singular and quote it
# shellcheck disable=SC2153
if [ -n "$INFLUXDB_URL" ] && [ "${INFLUXDB_URLS:0:1}" != "\"" ]; then
export INFLUXDB_URLS="\"$INFLUXDB_URLS\""
fi
echo "Building config.toml!"
envtpl > config.toml < config.toml.tpl | sed '/^$/d'
echo "Finished building toml..."
echo "###########################################"
echo "###########################################"
cat config.toml
echo "###########################################"
echo "###########################################"
telegraf -config config.toml -quiet