/collectors/charts.d.plugin: format modules (#7973)
* /collectors/charts.d.plugin: format ap.chart.sh * /collectors/charts.d.plugin: format apcupsd.chart.sh * /collectors/charts.d.plugin: format example.chart.sh * /collectors/charts.d.plugin: format libreswan.chart.sh * /collectors/charts.d.plugin: format nut.chart.sh * /collectors/charts.d.plugin: format opensips.chart.sh * /collectors/charts.d.plugin: shellcheck fixes
Ilya Mashchenko committed
Feb 7, 2020 at 00:50 UTC
d8fedbf3413ae5e4a0a3be8741efe77f1f1ad0c3
6 files changed
+391
-391
collectors/charts.d.plugin/ap/ap.chart.sh
+30
-30
@@ -16,9 +16,9 @@ declare -A ap_devs=()
16
17
# _check is called once, to find out if this chart should be enabled or not
18
ap_check() {
19
- require_cmd iw || return 1
20
- local ev
21
- ev=$(run iw dev | awk '
19
+ require_cmd iw || return 1
20
+ local ev
21
+ ev=$(run iw dev | awk '
22
BEGIN {
23
i = "";
24
ssid = "";
@@ -41,26 +41,26 @@ ap_check() {
41
}
42
}
43
')
44
- eval "${ev}"
44
+ eval "${ev}"
45
46
- # this should return:
47
- # - 0 to enable the chart
48
- # - 1 to disable the chart
46
+ # this should return:
47
+ # - 0 to enable the chart
48
+ # - 1 to disable the chart
49
50
- [ ${#ap_devs[@]} -gt 0 ] && return 0
51
- error "no devices found in AP mode, with 'iw dev'"
52
- return 1
50
+ [ ${#ap_devs[@]} -gt 0 ] && return 0
51
+ error "no devices found in AP mode, with 'iw dev'"
52
+ return 1
53
}
54
55
# _create is called once, to create the charts
56
ap_create() {
57
- local ssid dev
57
+ local ssid dev
58
59
- for dev in "${!ap_devs[@]}"; do
60
- ssid="${ap_devs[${dev}]}"
59
+ for dev in "${!ap_devs[@]}"; do
60
+ ssid="${ap_devs[${dev}]}"
61
62
- # create the chart with 3 dimensions
63
- cat <<EOF
62
+ # create the chart with 3 dimensions
63
+ cat << EOF
64
CHART ap_clients.${dev} '' "Connected clients to ${ssid} on ${dev}" "clients" ${dev} ap.clients line $((ap_priority + 1)) $ap_update_every
65
DIMENSION clients '' absolute 1 1
66
@@ -84,25 +84,25 @@ DIMENSION receive '' absolute 1 1000
84
DIMENSION transmit '' absolute -1 1000
85
DIMENSION expected 'expected throughput' absolute 1 1000
86
EOF
87
- done
87
+ done
88
89
- return 0
89
+ return 0
90
}
91
92
# _update is called continuously, to collect the values
93
ap_update() {
94
- # the first argument to this function is the microseconds since last update
95
- # pass this parameter to the BEGIN statement (see bellow).
96
-
97
- # do all the work to collect / calculate the values
98
- # for each dimension
99
- # remember: KEEP IT SIMPLE AND SHORT
100
-
101
- for dev in "${!ap_devs[@]}"; do
102
- echo
103
- echo "DEVICE ${dev}"
104
- iw "${dev}" station dump
105
- done | awk '
94
+ # the first argument to this function is the microseconds since last update
95
+ # pass this parameter to the BEGIN statement (see bellow).
96
+
97
+ # do all the work to collect / calculate the values
98
+ # for each dimension
99
+ # remember: KEEP IT SIMPLE AND SHORT
100
+
101
+ for dev in "${!ap_devs[@]}"; do
102
+ echo
103
+ echo "DEVICE ${dev}"
104
+ iw "${dev}" station dump
105
+ done | awk '
106
function zero_data() {
107
dev = "";
108
c = 0;
@@ -175,5 +175,5 @@ ap_update() {
175
}
176
'
177
178
- return 0
178
+ return 0
179
}
collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh
+64
-64
@@ -11,7 +11,7 @@ apcupsd_ip=
11
apcupsd_port=
12
13
declare -A apcupsd_sources=(
14
- ["local"]="127.0.0.1:3551"
14
+ ["local"]="127.0.0.1:3551"
15
)
16
17
# how frequently to collect UPS data
@@ -23,55 +23,55 @@ apcupsd_timeout=3
23
apcupsd_priority=90000
24
25
apcupsd_get() {
26
- run -t $apcupsd_timeout apcaccess status "$1"
26
+ run -t $apcupsd_timeout apcaccess status "$1"
27
}
28
29
apcupsd_check() {
30
31
- # this should return:
32
- # - 0 to enable the chart
33
- # - 1 to disable the chart
34
-
35
- require_cmd apcaccess || return 1
36
-
37
- # backwards compatibility
38
- if [ "${apcupsd_ip}:${apcupsd_port}" != ":" ]; then
39
- apcupsd_sources["local"]="${apcupsd_ip}:${apcupsd_port}"
40
- fi
41
-
42
- local host working=0 failed=0
43
- for host in "${!apcupsd_sources[@]}"; do
44
- run apcupsd_get "${apcupsd_sources[${host}]}" >/dev/null
45
- # shellcheck disable=2181
46
- if [ $? -ne 0 ]; then
47
- error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}."
48
- failed=$((failed + 1))
49
- else
50
- apcupsd_status="$(apcupsd_get ${apcupsd_sources[${host}]} | awk '/^STATUS.*/{ print $3 }')"
51
- if [ "${apcupsd_status}" != "ONLINE" ] && [ "${apcupsd_status}" != "ONBATT" ]; then
52
- error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online."
53
- failed=$((failed + 1))
54
- else
55
- working=$((working + 1))
56
- fi
57
- fi
58
- done
59
-
60
- if [ ${working} -eq 0 ]; then
61
- error "No APC UPSes found available."
62
- return 1
63
- fi
64
-
65
- return 0
31
+ # this should return:
32
+ # - 0 to enable the chart
33
+ # - 1 to disable the chart
34
+
35
+ require_cmd apcaccess || return 1
36
+
37
+ # backwards compatibility
38
+ if [ "${apcupsd_ip}:${apcupsd_port}" != ":" ]; then
39
+ apcupsd_sources["local"]="${apcupsd_ip}:${apcupsd_port}"
40
+ fi
41
+
42
+ local host working=0 failed=0
43
+ for host in "${!apcupsd_sources[@]}"; do
44
+ run apcupsd_get "${apcupsd_sources[${host}]}" > /dev/null
45
+ # shellcheck disable=2181
46
+ if [ $? -ne 0 ]; then
47
+ error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}."
48
+ failed=$((failed + 1))
49
+ else
50
+ apcupsd_status="$(apcupsd_get ${apcupsd_sources[${host}]} | awk '/^STATUS.*/{ print $3 }')"
51
+ if [ "${apcupsd_status}" != "ONLINE" ] && [ "${apcupsd_status}" != "ONBATT" ]; then
52
+ error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online."
53
+ failed=$((failed + 1))
54
+ else
55
+ working=$((working + 1))
56
+ fi
57
+ fi
58
+ done
59
+
60
+ if [ ${working} -eq 0 ]; then
61
+ error "No APC UPSes found available."
62
+ return 1
63
+ fi
64
+
65
+ return 0
66
}
67
68
apcupsd_create() {
69
- local host src
70
- for host in "${!apcupsd_sources[@]}"; do
71
- src=${apcupsd_sources[${host}]}
69
+ local host src
70
+ for host in "${!apcupsd_sources[@]}"; do
71
+ src=${apcupsd_sources[${host}]}
72
73
- # create the charts
74
- cat <<EOF
73
+ # create the charts
74
+ cat << EOF
75
CHART apcupsd_${host}.charge '' "UPS Charge for ${host} on ${src}" "percentage" ups apcupsd.charge area $((apcupsd_priority + 1)) $apcupsd_update_every
76
DIMENSION battery_charge charge absolute 1 100
77
@@ -104,21 +104,21 @@ CHART apcupsd_${host}.online '' "UPS ONLINE flag for ${host} on ${src}" "boolean
104
DIMENSION online online absolute 0 1
105
106
EOF
107
- done
108
- return 0
107
+ done
108
+ return 0
109
}
110
111
apcupsd_update() {
112
- # the first argument to this function is the microseconds since last update
113
- # pass this parameter to the BEGIN statement (see bellow).
112
+ # the first argument to this function is the microseconds since last update
113
+ # pass this parameter to the BEGIN statement (see bellow).
114
115
- # do all the work to collect / calculate the values
116
- # for each dimension
117
- # remember: KEEP IT SIMPLE AND SHORT
115
+ # do all the work to collect / calculate the values
116
+ # for each dimension
117
+ # remember: KEEP IT SIMPLE AND SHORT
118
119
- local host working=0 failed=0
120
- for host in "${!apcupsd_sources[@]}"; do
121
- apcupsd_get "${apcupsd_sources[${host}]}" | awk "
119
+ local host working=0 failed=0
120
+ for host in "${!apcupsd_sources[@]}"; do
121
+ apcupsd_get "${apcupsd_sources[${host}]}" | awk "
122
123
BEGIN {
124
battery_charge = 0;
@@ -190,16 +190,16 @@ END {
190
print \"END\"
191
}
192
}"
193
- # shellcheck disable=SC2181
194
- if [ $? -ne 0 ]; then
195
- failed=$((failed + 1))
196
- error "failed to get values for APC UPS ${host} on ${apcupsd_sources[${host}]}" && return 1
197
- else
198
- working=$((working + 1))
199
- fi
200
- done
201
-
202
- [ $working -eq 0 ] && error "failed to get values from all APC UPSes" && return 1
203
-
204
- return 0
193
+ # shellcheck disable=SC2181
194
+ if [ $? -ne 0 ]; then
195
+ failed=$((failed + 1))
196
+ error "failed to get values for APC UPS ${host} on ${apcupsd_sources[${host}]}" && return 1
197
+ else
198
+ working=$((working + 1))
199
+ fi
200
+ done
201
+
202
+ [ $working -eq 0 ] && error "failed to get values from all APC UPSes" && return 1
203
+
204
+ return 0
205
}
collectors/charts.d.plugin/example/example.chart.sh
+53
-53
@@ -32,63 +32,63 @@ example_last=0
32
example_count=0
33
34
example_get() {
35
- # do all the work to collect / calculate the values
36
- # for each dimension
37
- #
38
- # Remember:
39
- # 1. KEEP IT SIMPLE AND SHORT
40
- # 2. AVOID FORKS (avoid piping commands)
41
- # 3. AVOID CALLING TOO MANY EXTERNAL PROGRAMS
42
- # 4. USE LOCAL VARIABLES (global variables may overlap with other modules)
43
-
44
- example_value1=$RANDOM
45
- example_value2=$RANDOM
46
- example_value3=$RANDOM
47
- example_value4=$((8192 + (RANDOM * 16383 / 32767)))
48
-
49
- if [ $example_count -gt 0 ]; then
50
- example_count=$((example_count - 1))
51
-
52
- [ $example_last -gt 16383 ] && example_value4=$((example_last + (RANDOM * ((32767 - example_last) / 2) / 32767)))
53
- [ $example_last -le 16383 ] && example_value4=$((example_last - (RANDOM * (example_last / 2) / 32767)))
54
- else
55
- example_count=$((1 + (RANDOM * 5 / 32767)))
56
-
57
- if [ $example_last -gt 16383 ] && [ $example_value4 -gt 16383 ]; then
58
- example_value4=$((example_value4 - 16383))
59
- fi
60
- if [ $example_last -le 16383 ] && [ $example_value4 -lt 16383 ]; then
61
- example_value4=$((example_value4 + 16383))
62
- fi
63
- fi
64
- example_last=$example_value4
65
-
66
- # this should return:
67
- # - 0 to send the data to netdata
68
- # - 1 to report a failure to collect the data
69
-
70
- return 0
35
+ # do all the work to collect / calculate the values
36
+ # for each dimension
37
+ #
38
+ # Remember:
39
+ # 1. KEEP IT SIMPLE AND SHORT
40
+ # 2. AVOID FORKS (avoid piping commands)
41
+ # 3. AVOID CALLING TOO MANY EXTERNAL PROGRAMS
42
+ # 4. USE LOCAL VARIABLES (global variables may overlap with other modules)
43
+
44
+ example_value1=$RANDOM
45
+ example_value2=$RANDOM
46
+ example_value3=$RANDOM
47
+ example_value4=$((8192 + (RANDOM * 16383 / 32767)))
48
+
49
+ if [ $example_count -gt 0 ]; then
50
+ example_count=$((example_count - 1))
51
+
52
+ [ $example_last -gt 16383 ] && example_value4=$((example_last + (RANDOM * ((32767 - example_last) / 2) / 32767)))
53
+ [ $example_last -le 16383 ] && example_value4=$((example_last - (RANDOM * (example_last / 2) / 32767)))
54
+ else
55
+ example_count=$((1 + (RANDOM * 5 / 32767)))
56
+
57
+ if [ $example_last -gt 16383 ] && [ $example_value4 -gt 16383 ]; then
58
+ example_value4=$((example_value4 - 16383))
59
+ fi
60
+ if [ $example_last -le 16383 ] && [ $example_value4 -lt 16383 ]; then
61
+ example_value4=$((example_value4 + 16383))
62
+ fi
63
+ fi
64
+ example_last=$example_value4
65
+
66
+ # this should return:
67
+ # - 0 to send the data to netdata
68
+ # - 1 to report a failure to collect the data
69
+
70
+ return 0
71
}
72
73
# _check is called once, to find out if this chart should be enabled or not
74
example_check() {
75
- # this should return:
76
- # - 0 to enable the chart
77
- # - 1 to disable the chart
75
+ # this should return:
76
+ # - 0 to enable the chart
77
+ # - 1 to disable the chart
78
79
- # check something
80
- [ "${example_magic_number}" != "12345" ] && error "manual configuration required: you have to set example_magic_number=$example_magic_number in example.conf to start example chart." && return 1
79
+ # check something
80
+ [ "${example_magic_number}" != "12345" ] && error "manual configuration required: you have to set example_magic_number=$example_magic_number in example.conf to start example chart." && return 1
81
82
- # check that we can collect data
83
- example_get || return 1
82
+ # check that we can collect data
83
+ example_get || return 1
84
85
- return 0
85
+ return 0
86
}
87
88
# _create is called once, to create the charts
89
example_create() {
90
- # create the chart with 3 dimensions
91
- cat <<EOF
90
+ # create the chart with 3 dimensions
91
+ cat << EOF
92
CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked $((example_priority)) $example_update_every
93
DIMENSION random1 '' percentage-of-absolute-row 1 1
94
DIMENSION random2 '' percentage-of-absolute-row 1 1
@@ -97,18 +97,18 @@ CHART example.random2 '' "A random number" "random number" random random area $(
97
DIMENSION random '' absolute 1 1
98
EOF
99
100
- return 0
100
+ return 0
101
}
102
103
# _update is called continuously, to collect the values
104
example_update() {
105
- # the first argument to this function is the microseconds since last update
106
- # pass this parameter to the BEGIN statement (see bellow).
105
+ # the first argument to this function is the microseconds since last update
106
+ # pass this parameter to the BEGIN statement (see bellow).
107
108
- example_get || return 1
108
+ example_get || return 1
109
110
- # write the result of the work.
111
- cat <<VALUESEOF
110
+ # write the result of the work.
111
+ cat << VALUESEOF
112
BEGIN example.random $1
113
SET random1 = $example_value1
114
SET random2 = $example_value2
@@ -119,5 +119,5 @@ SET random = $example_value4
119
END
120
VALUESEOF
121
122
- return 0
122
+ return 0
123
}
collectors/charts.d.plugin/libreswan/libreswan.chart.sh
+73
-73
@@ -39,76 +39,76 @@ declare -A libreswan_tunnel_charts=()
39
40
# run the ipsec command
41
libreswan_ipsec() {
42
- if [ ${libreswan_sudo} -ne 0 ]; then
43
- sudo -n "${IPSEC_CMD}" "${@}"
44
- return $?
45
- else
46
- "${IPSEC_CMD}" "${@}"
47
- return $?
48
- fi
42
+ if [ ${libreswan_sudo} -ne 0 ]; then
43
+ sudo -n "${IPSEC_CMD}" "${@}"
44
+ return $?
45
+ else
46
+ "${IPSEC_CMD}" "${@}"
47
+ return $?
48
+ fi
49
}
50
51
# fetch latest values - fill the arrays
52
libreswan_get() {
53
- # do all the work to collect / calculate the values
54
- # for each dimension
55
-
56
- # empty the variables
57
- libreswan_traffic_in=()
58
- libreswan_traffic_out=()
59
- libreswan_established_add_time=()
60
- libreswan_connected_tunnels=()
61
-
62
- # convert the ipsec command output to a shell script
63
- # and source it to get the values
64
- # shellcheck disable=SC1090
65
- source <(
66
- {
67
- libreswan_ipsec whack --status
68
- libreswan_ipsec whack --trafficstatus
69
- } | sed -n \
70
- -e "s|[0-9]\+ #\([0-9]\+\): \"\(.*\)\".*IPsec SA established.*newest IPSEC.*|libreswan_connected_tunnels[\"\1\"]=\"\2\"|p" \
71
- -e "s|[0-9]\+ #\([0-9]\+\): \"\(.*\)\",.* add_time=\([0-9]\+\),.* inBytes=\([0-9]\+\),.* outBytes=\([0-9]\+\).*|libreswan_traffic_in[\"\1\"]=\"\4\"; libreswan_traffic_out[\"\1\"]=\"\5\"; libreswan_established_add_time[\"\1\"]=\"\3\";|p"
72
- ) || return 1
73
-
74
- # check we got some data
75
- [ ${#libreswan_connected_tunnels[@]} -eq 0 ] && return 1
76
-
77
- return 0
53
+ # do all the work to collect / calculate the values
54
+ # for each dimension
55
+
56
+ # empty the variables
57
+ libreswan_traffic_in=()
58
+ libreswan_traffic_out=()
59
+ libreswan_established_add_time=()
60
+ libreswan_connected_tunnels=()
61
+
62
+ # convert the ipsec command output to a shell script
63
+ # and source it to get the values
64
+ # shellcheck disable=SC1090
65
+ source <(
66
+ {
67
+ libreswan_ipsec whack --status
68
+ libreswan_ipsec whack --trafficstatus
69
+ } | sed -n \
70
+ -e "s|[0-9]\+ #\([0-9]\+\): \"\(.*\)\".*IPsec SA established.*newest IPSEC.*|libreswan_connected_tunnels[\"\1\"]=\"\2\"|p" \
71
+ -e "s|[0-9]\+ #\([0-9]\+\): \"\(.*\)\",.* add_time=\([0-9]\+\),.* inBytes=\([0-9]\+\),.* outBytes=\([0-9]\+\).*|libreswan_traffic_in[\"\1\"]=\"\4\"; libreswan_traffic_out[\"\1\"]=\"\5\"; libreswan_established_add_time[\"\1\"]=\"\3\";|p"
72
+ ) || return 1
73
+
74
+ # check we got some data
75
+ [ ${#libreswan_connected_tunnels[@]} -eq 0 ] && return 1
76
+
77
+ return 0
78
}
79
80
# _check is called once, to find out if this chart should be enabled or not
81
libreswan_check() {
82
- # this should return:
83
- # - 0 to enable the chart
84
- # - 1 to disable the chart
82
+ # this should return:
83
+ # - 0 to enable the chart
84
+ # - 1 to disable the chart
85
86
- require_cmd ipsec || return 1
86
+ require_cmd ipsec || return 1
87
88
- # make sure it is libreswan
89
- # shellcheck disable=SC2143
90
- if [ -z "$(ipsec --version | grep -i libreswan)" ]; then
91
- error "ipsec command is not Libreswan. Disabling Libreswan plugin."
92
- return 1
93
- fi
88
+ # make sure it is libreswan
89
+ # shellcheck disable=SC2143
90
+ if [ -z "$(ipsec --version | grep -i libreswan)" ]; then
91
+ error "ipsec command is not Libreswan. Disabling Libreswan plugin."
92
+ return 1
93
+ fi
94
95
- # check that we can collect data
96
- libreswan_get || return 1
95
+ # check that we can collect data
96
+ libreswan_get || return 1
97
98
- return 0
98
+ return 0
99
}
100
101
# create the charts for an ipsec tunnel
102
libreswan_create_one() {
103
- local n="${1}" name
103
+ local n="${1}" name
104
105
- name="${libreswan_connected_tunnels[${n}]}"
105
+ name="${libreswan_connected_tunnels[${n}]}"
106
107
- [ ! -z "${libreswan_tunnel_charts[${name}]}" ] && return 0
107
+ [ -n "${libreswan_tunnel_charts[${name}]}" ] && return 0
108
109
- libreswan_tunnel_charts[${name}]="$(fixid "${name}")"
109
+ libreswan_tunnel_charts[${name}]="$(fixid "${name}")"
110
111
- cat <<EOF
111
+ cat << EOF
112
CHART libreswan.${libreswan_tunnel_charts[${name}]}_net '${name}_net' "LibreSWAN Tunnel ${name} Traffic" "kilobits/s" "${name}" libreswan.net area $((libreswan_priority)) $libreswan_update_every
113
DIMENSION in '' incremental 8 1000
114
DIMENSION out '' incremental -8 1000
@@ -116,35 +116,35 @@ CHART libreswan.${libreswan_tunnel_charts[${name}]}_uptime '${name}_uptime' "Lib
116
DIMENSION uptime '' absolute 1 1
117
EOF
118
119
- return 0
119
+ return 0
120
121
}
122
123
# _create is called once, to create the charts
124
libreswan_create() {
125
- local n
126
- for n in "${!libreswan_connected_tunnels[@]}"; do
127
- libreswan_create_one "${n}"
128
- done
129
- return 0
125
+ local n
126
+ for n in "${!libreswan_connected_tunnels[@]}"; do
127
+ libreswan_create_one "${n}"
128
+ done
129
+ return 0
130
}
131
132
libreswan_now=$(date +%s)
133
134
# send the values to netdata for an ipsec tunnel
135
libreswan_update_one() {
136
- local n="${1}" microseconds="${2}" name id uptime
136
+ local n="${1}" microseconds="${2}" name id uptime
137
138
- name="${libreswan_connected_tunnels[${n}]}"
139
- id="${libreswan_tunnel_charts[${name}]}"
138
+ name="${libreswan_connected_tunnels[${n}]}"
139
+ id="${libreswan_tunnel_charts[${name}]}"
140
141
- [ -z "${id}" ] && libreswan_create_one "${name}"
141
+ [ -z "${id}" ] && libreswan_create_one "${name}"
142
143
- uptime=$((libreswan_now - libreswan_established_add_time[${n}]))
144
- [ ${uptime} -lt 0 ] && uptime=0
143
+ uptime=$((libreswan_now - libreswan_established_add_time[${n}]))
144
+ [ ${uptime} -lt 0 ] && uptime=0
145
146
- # write the result of the work.
147
- cat <<VALUESEOF
146
+ # write the result of the work.
147
+ cat << VALUESEOF
148
BEGIN libreswan.${id}_net ${microseconds}
149
SET in = ${libreswan_traffic_in[${n}]}
150
SET out = ${libreswan_traffic_out[${n}]}
@@ -157,16 +157,16 @@ VALUESEOF
157
158
# _update is called continiously, to collect the values
159
libreswan_update() {
160
- # the first argument to this function is the microseconds since last update
161
- # pass this parameter to the BEGIN statement (see bellow).
160
+ # the first argument to this function is the microseconds since last update
161
+ # pass this parameter to the BEGIN statement (see bellow).
162
163
- libreswan_get || return 1
164
- libreswan_now=$(date +%s)
163
+ libreswan_get || return 1
164
+ libreswan_now=$(date +%s)
165
166
- local n
167
- for n in "${!libreswan_connected_tunnels[@]}"; do
168
- libreswan_update_one "${n}" "${@}"
169
- done
166
+ local n
167
+ for n in "${!libreswan_connected_tunnels[@]}"; do
168
+ libreswan_update_one "${n}" "${@}"
169
+ done
170
171
- return 0
171
+ return 0
172
}
collectors/charts.d.plugin/nut/nut.chart.sh
+60
-60
@@ -28,59 +28,59 @@ declare -A nut_ids=()
28
declare -A nut_names=()
29
30
nut_get_all() {
31
- run -t $nut_timeout upsc -l
31
+ run -t $nut_timeout upsc -l
32
}
33
34
nut_get() {
35
- run -t $nut_timeout upsc "$1"
35
+ run -t $nut_timeout upsc "$1"
36
37
- if [ "${nut_clients_chart}" -eq "1" ]; then
38
- printf "ups.connected_clients: "
39
- run -t $nut_timeout upsc -c "$1" | wc -l
40
- fi
37
+ if [ "${nut_clients_chart}" -eq "1" ]; then
38
+ printf "ups.connected_clients: "
39
+ run -t $nut_timeout upsc -c "$1" | wc -l
40
+ fi
41
}
42
43
nut_check() {
44
45
- # this should return:
46
- # - 0 to enable the chart
47
- # - 1 to disable the chart
48
-
49
- local x
50
-
51
- require_cmd upsc || return 1
52
-
53
- [ -z "$nut_ups" ] && nut_ups="$(nut_get_all)"
54
-
55
- for x in $nut_ups; do
56
- nut_get "$x" >/dev/null
57
- # shellcheck disable=SC2181
58
- if [ $? -eq 0 ]; then
59
- if [ ! -z "${nut_names[${x}]}" ]; then
60
- nut_ids[$x]="$(fixid "${nut_names[${x}]}")"
61
- else
62
- nut_ids[$x]="$(fixid "$x")"
63
- fi
64
- continue
65
- fi
66
- error "cannot get information for NUT UPS '$x'."
67
- done
68
-
69
- if [ ${#nut_ids[@]} -eq 0 ]; then
70
- # shellcheck disable=SC2154
71
- error "Cannot find UPSes - please set nut_ups='ups_name' in $confd/nut.conf"
72
- return 1
73
- fi
74
-
75
- return 0
45
+ # this should return:
46
+ # - 0 to enable the chart
47
+ # - 1 to disable the chart
48
+
49
+ local x
50
+
51
+ require_cmd upsc || return 1
52
+
53
+ [ -z "$nut_ups" ] && nut_ups="$(nut_get_all)"
54
+
55
+ for x in $nut_ups; do
56
+ nut_get "$x" > /dev/null
57
+ # shellcheck disable=SC2181
58
+ if [ $? -eq 0 ]; then
59
+ if [ -n "${nut_names[${x}]}" ]; then
60
+ nut_ids[$x]="$(fixid "${nut_names[${x}]}")"
61
+ else
62
+ nut_ids[$x]="$(fixid "$x")"
63
+ fi
64
+ continue
65
+ fi
66
+ error "cannot get information for NUT UPS '$x'."
67
+ done
68
+
69
+ if [ ${#nut_ids[@]} -eq 0 ]; then
70
+ # shellcheck disable=SC2154
71
+ error "Cannot find UPSes - please set nut_ups='ups_name' in $confd/nut.conf"
72
+ return 1
73
+ fi
74
+
75
+ return 0
76
}
77
78
nut_create() {
79
- # create the charts
80
- local x
79
+ # create the charts
80
+ local x
81
82
- for x in "${nut_ids[@]}"; do
83
- cat <<EOF
82
+ for x in "${nut_ids[@]}"; do
83
+ cat << EOF
84
CHART nut_$x.charge '' "UPS Charge" "percentage" ups nut.charge area $((nut_priority + 1)) $nut_update_every
85
DIMENSION battery_charge charge absolute 1 100
86
@@ -115,30 +115,30 @@ CHART nut_$x.temp '' "UPS Temperature" "temperature" ups nut.temperature line $(
115
DIMENSION temp temp absolute 1 100
116
EOF
117
118
- if [ "${nut_clients_chart}" = "1" ]; then
119
- cat <<EOF2
118
+ if [ "${nut_clients_chart}" = "1" ]; then
119
+ cat << EOF2
120
CHART nut_$x.clients '' "UPS Connected Clients" "clients" ups nut.clients area $((nut_priority + 9)) $nut_update_every
121
DIMENSION clients '' absolute 1 1
122
EOF2
123
- fi
123
+ fi
124
125
- done
125
+ done
126
127
- return 0
127
+ return 0
128
}
129
130
nut_update() {
131
- # the first argument to this function is the microseconds since last update
132
- # pass this parameter to the BEGIN statement (see bellow).
131
+ # the first argument to this function is the microseconds since last update
132
+ # pass this parameter to the BEGIN statement (see bellow).
133
134
- # do all the work to collect / calculate the values
135
- # for each dimension
136
- # remember: KEEP IT SIMPLE AND SHORT
134
+ # do all the work to collect / calculate the values
135
+ # for each dimension
136
+ # remember: KEEP IT SIMPLE AND SHORT
137
138
- local i x
139
- for i in "${!nut_ids[@]}"; do
140
- x="${nut_ids[$i]}"
141
- nut_get "$i" | awk "
138
+ local i x
139
+ for i in "${!nut_ids[@]}"; do
140
+ x="${nut_ids[$i]}"
141
+ nut_get "$i" | awk "
142
BEGIN {
143
battery_charge = 0;
144
battery_runtime = 0;
@@ -223,10 +223,10 @@ END {
223
print \"END\"
224
}
225
}"
226
- # shellcheck disable=2181
227
- [ $? -ne 0 ] && unset "nut_ids[$i]" && error "failed to get values for '$i', disabling it."
228
- done
226
+ # shellcheck disable=2181
227
+ [ $? -ne 0 ] && unset "nut_ids[$i]" && error "failed to get values for '$i', disabling it."
228
+ done
229
230
- [ ${#nut_ids[@]} -eq 0 ] && error "no UPSes left active." && return 1
231
- return 0
230
+ [ ${#nut_ids[@]} -eq 0 ] && error "no UPSes left active." && return 1
231
+ return 0
232
}
collectors/charts.d.plugin/opensips/opensips.chart.sh
+111
-111
@@ -14,40 +14,40 @@ opensips_timeout=2
14
opensips_priority=80000
15
16
opensips_get_stats() {
17
- run -t $opensips_timeout "$opensips_cmd" $opensips_opts |
18
- grep "^\(core\|dialog\|net\|registrar\|shmem\|siptrace\|sl\|tm\|uri\|usrloc\):[a-zA-Z0-9_-]\+[[:space:]]*[=:]\+[[:space:]]*[0-9]\+[[:space:]]*$" |
19
- sed \
20
- -e "s|[[:space:]]*[=:]\+[[:space:]]*\([0-9]\+\)[[:space:]]*$|=\1|g" \
21
- -e "s|[[:space:]:-]\+|_|g" \
22
- -e "s|^|opensips_|g"
23
-
24
- local ret=$?
25
- [ $ret -ne 0 ] && echo "opensips_command_failed=1"
26
- return $ret
17
+ run -t $opensips_timeout "$opensips_cmd" $opensips_opts |
18
+ grep "^\(core\|dialog\|net\|registrar\|shmem\|siptrace\|sl\|tm\|uri\|usrloc\):[a-zA-Z0-9_-]\+[[:space:]]*[=:]\+[[:space:]]*[0-9]\+[[:space:]]*$" |
19
+ sed \
20
+ -e "s|[[:space:]]*[=:]\+[[:space:]]*\([0-9]\+\)[[:space:]]*$|=\1|g" \
21
+ -e "s|[[:space:]:-]\+|_|g" \
22
+ -e "s|^|opensips_|g"
23
+
24
+ local ret=$?
25
+ [ $ret -ne 0 ] && echo "opensips_command_failed=1"
26
+ return $ret
27
}
28
29
opensips_check() {
30
- # if the user did not provide an opensips_cmd
31
- # try to find it in the system
32
- if [ -z "$opensips_cmd" ]; then
33
- require_cmd opensipsctl || return 1
34
- fi
35
-
36
- # check once if the command works
37
- local x
38
- x="$(opensips_get_stats | grep "^opensips_core_")"
39
- # shellcheck disable=SC2181
40
- if [ ! $? -eq 0 ] || [ -z "$x" ]; then
41
- error "cannot get global status. Please set opensips_opts='options' whatever needed to get connected to opensips server, in $confd/opensips.conf"
42
- return 1
43
- fi
44
-
45
- return 0
30
+ # if the user did not provide an opensips_cmd
31
+ # try to find it in the system
32
+ if [ -z "$opensips_cmd" ]; then
33
+ require_cmd opensipsctl || return 1
34
+ fi
35
+
36
+ # check once if the command works
37
+ local x
38
+ x="$(opensips_get_stats | grep "^opensips_core_")"
39
+ # shellcheck disable=SC2181
40
+ if [ ! $? -eq 0 ] || [ -z "$x" ]; then
41
+ error "cannot get global status. Please set opensips_opts='options' whatever needed to get connected to opensips server, in $confd/opensips.conf"
42
+ return 1
43
+ fi
44
+
45
+ return 0
46
}
47
48
opensips_create() {
49
- # create the charts
50
- cat <<EOF
49
+ # create the charts
50
+ cat << EOF
51
CHART opensips.dialogs_active '' "OpenSIPS Active Dialogs" "dialogs" dialogs '' area $((opensips_priority + 1)) $opensips_update_every
52
DIMENSION dialog_active_dialogs active absolute 1 1
53
DIMENSION dialog_early_dialogs early absolute -1 1
@@ -141,91 +141,91 @@ CHART opensips.shmem_fragments '' "OpenSIPS Shared Memory Fragmentation" "fragme
141
DIMENSION shmem_fragments fragments absolute 1 1
142
EOF
143
144
- return 0
144
+ return 0
145
}
146
147
opensips_update() {
148
- # the first argument to this function is the microseconds since last update
149
- # pass this parameter to the BEGIN statement (see bellow).
150
-
151
- # do all the work to collect / calculate the values
152
- # for each dimension
153
-
154
- # 1. get the counters page from opensips
155
- # 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local opensips_
156
- # 3. egrep lines starting with:
157
- # local opensips_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
158
- # local opensips_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
159
- # 4. then execute this as a script with the eval
160
- # be very carefull with eval:
161
- # prepare the script and always grep at the end the lines that are usefull, so that
162
- # even if something goes wrong, no other code can be executed
163
-
164
- unset \
165
- opensips_dialog_active_dialogs \
166
- opensips_dialog_early_dialogs \
167
- opensips_usrloc_registered_users \
168
- opensips_usrloc_location_users \
169
- opensips_usrloc_location_contacts \
170
- opensips_usrloc_location_expires \
171
- opensips_registrar_accepted_regs \
172
- opensips_registrar_rejected_regs \
173
- opensips_tm_UAS_transactions \
174
- opensips_tm_UAC_transactions \
175
- opensips_core_rcv_requests \
176
- opensips_core_rcv_replies \
177
- opensips_core_fwd_requests \
178
- opensips_core_fwd_replies \
179
- opensips_core_drop_requests \
180
- opensips_core_drop_replies \
181
- opensips_core_err_requests \
182
- opensips_core_err_replies \
183
- opensips_core_bad_URIs_rcvd \
184
- opensips_core_unsupported_methods \
185
- opensips_core_bad_msg_hdr \
186
- opensips_tm_received_replies \
187
- opensips_tm_relayed_replies \
188
- opensips_tm_local_replies \
189
- opensips_tm_2xx_transactions \
190
- opensips_tm_3xx_transactions \
191
- opensips_tm_4xx_transactions \
192
- opensips_tm_5xx_transactions \
193
- opensips_tm_6xx_transactions \
194
- opensips_tm_inuse_transactions \
195
- opensips_sl_1xx_replies \
196
- opensips_sl_2xx_replies \
197
- opensips_sl_3xx_replies \
198
- opensips_sl_4xx_replies \
199
- opensips_sl_5xx_replies \
200
- opensips_sl_6xx_replies \
201
- opensips_sl_sent_replies \
202
- opensips_sl_sent_err_replies \
203
- opensips_sl_received_ACKs \
204
- opensips_dialog_processed_dialogs \
205
- opensips_dialog_expired_dialogs \
206
- opensips_dialog_failed_dialogs \
207
- opensips_net_waiting_udp \
208
- opensips_net_waiting_tcp \
209
- opensips_uri_positive_checks \
210
- opensips_uri_negative_checks \
211
- opensips_siptrace_traced_requests \
212
- opensips_siptrace_traced_replies \
213
- opensips_shmem_total_size \
214
- opensips_shmem_used_size \
215
- opensips_shmem_real_used_size \
216
- opensips_shmem_max_used_size \
217
- opensips_shmem_free_size \
218
- opensips_shmem_fragments
219
-
220
- opensips_command_failed=0
221
- eval "local $(opensips_get_stats)"
222
- # shellcheck disable=SC2181
223
- [ $? -ne 0 ] && return 1
224
-
225
- [ $opensips_command_failed -eq 1 ] && error "failed to get values, disabling." && return 1
226
-
227
- # write the result of the work.
228
- cat <<VALUESEOF
148
+ # the first argument to this function is the microseconds since last update
149
+ # pass this parameter to the BEGIN statement (see bellow).
150
+
151
+ # do all the work to collect / calculate the values
152
+ # for each dimension
153
+
154
+ # 1. get the counters page from opensips
155
+ # 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local opensips_
156
+ # 3. egrep lines starting with:
157
+ # local opensips_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
158
+ # local opensips_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
159
+ # 4. then execute this as a script with the eval
160
+ # be very carefull with eval:
161
+ # prepare the script and always grep at the end the lines that are usefull, so that
162
+ # even if something goes wrong, no other code can be executed
163
+
164
+ unset \
165
+ opensips_dialog_active_dialogs \
166
+ opensips_dialog_early_dialogs \
167
+ opensips_usrloc_registered_users \
168
+ opensips_usrloc_location_users \
169
+ opensips_usrloc_location_contacts \
170
+ opensips_usrloc_location_expires \
171
+ opensips_registrar_accepted_regs \
172
+ opensips_registrar_rejected_regs \
173
+ opensips_tm_UAS_transactions \
174
+ opensips_tm_UAC_transactions \
175
+ opensips_core_rcv_requests \
176
+ opensips_core_rcv_replies \
177
+ opensips_core_fwd_requests \
178
+ opensips_core_fwd_replies \
179
+ opensips_core_drop_requests \
180
+ opensips_core_drop_replies \
181
+ opensips_core_err_requests \
182
+ opensips_core_err_replies \
183
+ opensips_core_bad_URIs_rcvd \
184
+ opensips_core_unsupported_methods \
185
+ opensips_core_bad_msg_hdr \
186
+ opensips_tm_received_replies \
187
+ opensips_tm_relayed_replies \
188
+ opensips_tm_local_replies \
189
+ opensips_tm_2xx_transactions \
190
+ opensips_tm_3xx_transactions \
191
+ opensips_tm_4xx_transactions \
192
+ opensips_tm_5xx_transactions \
193
+ opensips_tm_6xx_transactions \
194
+ opensips_tm_inuse_transactions \
195
+ opensips_sl_1xx_replies \
196
+ opensips_sl_2xx_replies \
197
+ opensips_sl_3xx_replies \
198
+ opensips_sl_4xx_replies \
199
+ opensips_sl_5xx_replies \
200
+ opensips_sl_6xx_replies \
201
+ opensips_sl_sent_replies \
202
+ opensips_sl_sent_err_replies \
203
+ opensips_sl_received_ACKs \
204
+ opensips_dialog_processed_dialogs \
205
+ opensips_dialog_expired_dialogs \
206
+ opensips_dialog_failed_dialogs \
207
+ opensips_net_waiting_udp \
208
+ opensips_net_waiting_tcp \
209
+ opensips_uri_positive_checks \
210
+ opensips_uri_negative_checks \
211
+ opensips_siptrace_traced_requests \
212
+ opensips_siptrace_traced_replies \
213
+ opensips_shmem_total_size \
214
+ opensips_shmem_used_size \
215
+ opensips_shmem_real_used_size \
216
+ opensips_shmem_max_used_size \
217
+ opensips_shmem_free_size \
218
+ opensips_shmem_fragments
219
+
220
+ opensips_command_failed=0
221
+ eval "local $(opensips_get_stats)"
222
+ # shellcheck disable=SC2181
223
+ [ $? -ne 0 ] && return 1
224
+
225
+ [ $opensips_command_failed -eq 1 ] && error "failed to get values, disabling." && return 1
226
+
227
+ # write the result of the work.
228
+ cat << VALUESEOF
229
BEGIN opensips.dialogs_active $1
230
SET dialog_active_dialogs = $opensips_dialog_active_dialogs
231
SET dialog_early_dialogs = $opensips_dialog_early_dialogs
@@ -320,5 +320,5 @@ SET shmem_fragments = $opensips_shmem_fragments
320
END
321
VALUESEOF
322
323
- return 0
323
+ return 0
324
}