-
Notifications
You must be signed in to change notification settings - Fork 8
/
nri-statsd.sh
executable file
·66 lines (51 loc) · 2 KB
/
nri-statsd.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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
set -eo pipefail
# Use environment variables to override the endpoints sub domains
NR_INSIGHTS_COLLECTOR="${NR_INSIGHTS_COLLECTOR:-insights-collector}"
NR_INSIGHTS_DOMAIN="newrelic.com"
NR_METRICS_COLLECTOR="${NR_METRICS_COLLECTOR:-metric-api}"
NR_METRICS_DOMAIN="newrelic.com"
if [ ! -z "${NR_EU_REGION}" ]; then
NR_INSIGHTS_DOMAIN="eu01.nr-data.net"
NR_METRICS_DOMAIN="eu."$NR_METRICS_DOMAIN
fi
if [ ! -z "${NR_GOV_COLLECTOR}" ]; then
NR_INSIGHTS_COLLECTOR="gov-insights-collector"
NR_METRICS_COLLECTOR="gov-infra-api"
fi
GO_STATSD_BIN=/bin/gostatsd
if [ ! -z "${HOSTNAME}" ]; then
GO_STATSD_BIN="/bin/gostatsd --hostname ${HOSTNAME}"
fi
if [ -z "${NR_STATSD_METRICS_ADDR}" ]; then
NR_STATSD_METRICS_ADDR=":8125"
fi
if [ -z "${NR_ENDPOINT_ADDR}" ]; then
NR_ENDPOINT_ADDR="https://${NR_INSIGHTS_COLLECTOR}.${NR_INSIGHTS_DOMAIN}/v1/accounts/${NR_ACCOUNT_ID}/events"
fi
if [ -z "${NR_ENDPOINT_METRICS_ADDR}" ]; then
NR_ENDPOINT_METRICS_ADDR="https://${NR_METRICS_COLLECTOR}.${NR_METRICS_DOMAIN}/metric/v1"
fi
# per FHS, host local software packages should be in /usr/local and their config files in /usr/local/etc
# could be argued that gostatsd is an optional package and therefore be in /opt/{package} and config files in /etc/opt/{package}..
# nevertheless, gostatsd binary is in /bin, but let's assume we are following fhs best pratices
export NR_STATSD_CFG=/etc/opt/newrelic/nri-statsd.toml
if [ ! -f "${NR_STATSD_CFG}" ]; then
/bin/cat <<EOF
WARNING: configuration file not found, generating one based on default values.
make sure you have provided the required NR_API_KEY and optionally
NR_ACCOUNT_ID if using Insights events, via environment variables.
EOF
export NR_STATSD_CFG=/tmp/nri-statsd.toml
/bin/cat <<EOM >${NR_STATSD_CFG}
backends='newrelic'
metrics-addr="${NR_STATSD_METRICS_ADDR}"
[newrelic]
flush-type = "metrics"
transport = "default"
address = "${NR_ENDPOINT_ADDR}"
address-metrics = "${NR_ENDPOINT_METRICS_ADDR}"
api-key = "${NR_API_KEY}"
EOM
fi
exec ./run-statsd.sh