forked from newrelic/dockerized-mysql-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-and-run-mysql-plugin
executable file
·102 lines (87 loc) · 2.28 KB
/
configure-and-run-mysql-plugin
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
root_dir=$(dirname $BASH_SOURCE[0])
will_exit=0
# Default the reported name based on monitored hostname
AGENT_NAME=${AGENT_NAME:-"${AGENT_HOST}"}
#
# First, check all the mandatory environment variables
#
for variable in \
NEW_RELIC_LICENSE_KEY NEW_RELIC_LOG_LEVEL \
AGENT_HOST AGENT_USER
do
eval target=\$$variable
if [ -z "${target}" ]; then
echo "Must set $variable environment variable!"
will_exit=1
fi
done
if [ 0 -ne $will_exit ]; then
echo "Exiting"
exit $will_exit
fi
# Then create the config dir if needed
mkdir -p "$root_dir/config/"
#
# and write the newrelic.json
#
echo '{' > "$root_dir/config/newrelic.json"
#
# Any variable that starts with NEW_RELIC_ is placed in the newrelic.json
# after the prefix is removed.
for variable in $(env | egrep ^NEW_RELIC_ | cut -f1 -d\=); do
eval value=\$$variable
eval key=$(echo $variable | cut -f3- -d\_ | tr A-Z a-z)
cat >> "$root_dir/config/newrelic.json" <<END_JSON
"${key}": "${value}",
END_JSON
done
# Proxy configuration
# PROXY_HOST - The proxy host (e.g. webcache.example.com)
# PROXY_PORT - The proxy port (e.g. 8080). Defaults to 80 if a proxy_host is set
# PROXY_USERNAME - The proxy username
# PROXY_PASSWORD - The proxy password
for variable in $(env | egrep ^PROXY_ | cut -f1 -d\=); do
eval value=\$$variable
eval key=$(echo $variable | tr A-Z a-z)
cat >> "$root_dir/config/newrelic.json" <<END_JSON
"${key}": "${value}",
END_JSON
done
# Write logs to /dev/null and close the config file
cat >> "$root_dir/config/newrelic.json" <<END_JSON
"log_file_name": "null",
"log_file_path": "/dev"
}
END_JSON
#
# Now write out the specific config for this plugin
#
cat > "$root_dir/config/plugin.json" <<END_JSON
{
"agents": [
{
END_JSON
for variable in $(env | egrep ^AGENT_ | cut -f1 -d\=); do
eval value=\$$variable
eval key=$(echo $variable | cut -f2- -d\_ | tr A-Z a-z)
cat >> "$root_dir/config/plugin.json" <<END_JSON
"${key}": "${value}",
END_JSON
done
cat >> "$root_dir/config/plugin.json" <<END_JSON
}
]
}
END_JSON
#
# Nothing should need to write to the filesystem
#
chmod -R a-w .
# A little bit of helpful debug output
echo >&2
echo "Gathering data from \"${AGENT_HOST}\"" >&2
echo "Reporting as \"${AGENT_NAME}\"" >&2
echo >&2
# Run the Plugin
exec java -Xmx128m -jar plugin.jar