-
Notifications
You must be signed in to change notification settings - Fork 28
/
install-collector.sh
107 lines (89 loc) · 3.99 KB
/
install-collector.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
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
103
104
105
106
107
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
# netdata
# real-time performance and health monitoring, done right!
# (C) 2022
# This script installs community maintained collectors from netdata/community github repo
# example usage:
# $ sudo wget -O /tmp/install-collector.sh https://raw.githubusercontent.com/netdata/community/main/utilities/install-collector.sh && sudo bash /tmp/install-collector.sh python.d.plugin/clickhouse
NETDATA_DIR="/etc/netdata"
if [ "$EUID" -ne 0 ]; then
printf "\nError: Please run as root.\n\n"
exit 1
elif [ $# -eq 0 ]; then
printf "\nError: No arguments supplied. \n\nUsage: sudo %s <plugin/collector> (Eg: %s charts.d.plugin/speedtest)\n\nFor available collectors from the community see https://github.com/netdata/community/tree/main/collectors\n\n" "$0" "$0"
exit 1
elif [ "$1" == "-h" ]; then
printf "\nUsage: sudo %s <plugin/collector> (Eg: %s charts.d.plugin/speedtest)\n\nFor available collectors from the community see https://github.com/netdata/community/tree/main/collectors\n\n" "$0" "$0"
exit 1
elif [ ! -d $NETDATA_DIR ]; then
printf "\nError: Please update NETDATA_DIR in %s with the Netdata user configuration directory as mentioned in https://learn.netdata.cloud/docs/agent/collectors/plugins.d#environment-variables\n\n" "$0"
exit 1
fi
printf "\nYou are about to install a collector that is NOT developed or maintained by Netdata. Would you like to proceed? [y/n]"
read -r answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then
printf "\nInstalling collector from community repo..."
else
printf "\n\nExiting...\n\n"
exit 1
fi
input=$1
collector=${input#*/}
suffix=".plugin/$collector"
plugin=${input%"$suffix"}
if [ "$plugin" == "python.d" ]; then
file_ext=".py"
elif [ "$plugin" == "charts.d" ]; then
file_ext=".sh"
elif [ "$plugin" == "go.d" ]; then
file_ext=".go"
elif [ "$plugin" == "node.d" ]; then
file_ext=".js"
fi
charts="https://raw.githubusercontent.com/netdata/community/main/collectors/$1/$collector.chart$file_ext"
config="https://raw.githubusercontent.com/netdata/community/main/collectors/$1/$collector.conf"
executable="/usr/libexec/netdata/$plugin/"
collector_conf="/etc/netdata/$plugin/"
conf="/etc/netdata/$plugin.conf"
enabled="\"$collector: yes\""
filecheck="$collector_conf/$collector.conf"
if [ -f "$filecheck" ]; then
printf "\n\nA Netdata collector by this name already exists on this system. Exiting...\n\n"
exit 1
fi
if command -v wget > /dev/null 2>&1; then
sudo wget "$charts" -P "$executable"
sudo wget "$config" -P "$collector_conf"
elif command -v curl > /dev/null 2>&1; then
cd "$executable" && { sudo curl -O "$charts" ; cd - || exit 1; }
cd "$collector_conf" && { sudo curl -O "$config" ; cd - || exit 1; }
else
printf "\n\nDownloading failed because neither curl nor wget are available on this system.\n\n"
exit 1
fi
if ! [ -f "$executable/$collector.chart$file_ext" ] && ! [ -f "$collector_conf/$collector.conf" ]; then
printf "\nDownloading failed. Please provide a valid input.\n\n"
exit 1
fi
sudo echo "$enabled" | tee -a "$conf"
if ! command -v systemctl &> /dev/null
then
printf "\nUnable to restart Netdata agent, please follow these instructions to restart manually: https://learn.netdata.cloud/docs/configure/start-stop-restart\n"
exit 1
fi
if systemctl is-active --quiet netdata; then
sudo systemctl restart netdata
if ! sudo systemctl restart netdata; then
printf "\nUnable to restart Netdata agent, please follow these instructions to restart manually: https://learn.netdata.cloud/docs/configure/start-stop-restart\n"
exit 1
fi
else
sudo service netdata restart
if ! sudo service netdata restart; then
printf "\nUnable to restart Netdata agent, please follow these instructions to restart manually: https://learn.netdata.cloud/docs/configure/start-stop-restart\n"
exit 1
fi
fi
printf "\nSuccessfully restarted Netdata agent."
printf "\n\nInstalled %s collector succesfully.\n\n" "$collector"