@cryptotaxi247 / netdata-1 / commits / de304fb61

added documentation; minor adjustments to charts.d collectors

Costa Tsaousis (ktsaou) committed Nov 18, 2015 at 23:31 UTC de304fb610479fcad40f2ff6b44fd2f875c90476
7 files changed +285 -22
charts.d/README.md
+192
@@ -1 +1,193 @@
1 +The following charts.d plugins are supported:
2 +
3 +# squid
4 +
5 +The plugin will monitor a squid server.
6 +
7 +It will produce 4 charts:
8 +
9 +1. Squid Client Bandwidth in kbps
10 +
11 + * in
12 + * out
13 + * hits
14 +
15 +2. Squid Client Requests in requests/sec
16 +
17 + * requests
18 + * hits
19 + * errors
20 +
21 +3. Squid Server Bandwidth
22 +
23 + * in
24 + * out
25 +
26 +4. Squid Server Requests
27 +
28 + * requests
29 + * errors
30 +
31 +## autoconfig
32 +
33 +The plugin will by itself detect squid servers running on
34 +localhost, on ports 3128 or 8080.
35 +
36 +It will attempt to download URLs in the form:
37 +
38 +- `cache_object://HOST:PORT/counters`
39 +- `/squid-internal-mgr/counters`
40 +
41 +If any succeeds, it will use this.
42 +
43 +## configuration
44 +
45 +If you need to configure it by hand, create the file
46 +`/etc/netdata/squid.conf` with the following variables:
47 +
48 +- `squid_host=IP` the IP of the squid host
49 +- `squid_port=PORT` the port the squid is listening
50 +- `squid_url="URL"` the URL with the statistics to be fetched from squid
51 +- `squid_timeout=SECONDS` how much time we should wait for squid to respond
52 +- `squid_update_every=SECONDS` the frequency of the data collection
53 +
54 +Example `/etc/netdata/squid.conf`:
55 +
56 +```sh
57 +squid_host=127.0.0.1
58 +squid_port=3128
59 +squid_url="cache_object://127.0.0.1:3128/counters"
60 +squid_timeout=2
61 +squid_update_every=5
62 +```
63 +
64 +---
65 +
66 +# sensors
67 +
68 +The plugin will provide charts for all configured system sensors
69 +
70 +> This plugin is reading sensors directly from the kernel.
71 +> The `lm-sensors` package is able to perform calculations on the
72 +> kernel provided values, this plugin will not perform.
73 +> So, the values graphed, are the raw hardware values of the sensors.
74 +
75 +The plugin will create netdata charts for:
76 +
77 +1. temperature
78 +2. voltage
79 +3. current
80 +4. power
81 +5. fans speed
82 +6. energy
83 +7. humidity
84 +
85 +One chart for every sensor chip found and each of the above will be created.
86 +
87 +## configuration
88 +
89 +This is the internal default for `/etc/netdata/sensors.conf`
90 +
91 +```sh
92 +# the directory the kernel keeps sensor data
93 +sensors_sys_dir="${NETDATA_HOST_PREFIX}/sys/devices"
94 +
95 +# how deep in the tree to check for sensor data
96 +sensors_sys_depth=10
97 +
98 +# if set to 1, the script will overwrite internal
99 +# script functions with code generated ones
100 +# leave to 1, is faster
101 +sensors_source_update=1
102 +
103 +# how frequently to collect sensor data
104 +# the default is to collect it at every iteration of charts.d
105 +sensors_update_every=
106 +```
107 +
108 +---
109 +
110 +# postfix
111 +
112 +The plugin will collect the postfix queue size.
113 +
114 +It will create two charts:
115 +
116 +1. queue size in emails
117 +2. queue size in KB
118 +
119 +## configuration
120 +
121 +This is the internal default for `/etc/netdata/postfix.conf`
122 +
123 +```sh
124 +# the postqueue command
125 +# if empty, it will use the one found in the system path
126 +postfix_postqueue=
127 +
128 +# how frequently to collect queue size
129 +postfix_update_every=15
130 +```
131 +
132 +---
133 +
134 +# nut
135 +
136 +The plugin will collect UPS data for all UPSes configured in the system.
137 +
138 +The following charts will be created:
139 +
140 +1. UPS Charge
141 +
142 + * percentage changed
143 +
144 +2. UPS Battery Voltage
145 +
146 + * current voltage
147 + * high voltage
148 + * low voltage
149 + * nominal voltage
150 +
151 +3. UPS Input Voltage
152 +
153 + * current voltage
154 + * fault voltage
155 + * nominal voltage
156 +
157 +4. UPS Input Current
158 +
159 + * nominal current
160 +
161 +5. UPS Input Frequency
162 +
163 + * current frequency
164 + * nominal frequency
165 +
166 +6. UPS Output Voltage
167 +
168 + * current voltage
169 +
170 +7. UPS Load
171 +
172 + * current load
173 +
174 +8. UPS Temperature
175 +
176 + * current temperature
177 +
178 +
179 +## configuration
180 +
181 +This is the internal default for `/etc/netdata/nut.conf`
182 +
183 +```sh
184 +# a space separated list of UPS names
185 +# if empty, the list returned by 'upsc -l' will be used
186 +nut_ups=
187 +
188 +# how frequently to collect UPS data
189 +nut_update_every=2
190 +```
191 +
192 +---
193
charts.d/nut.chart.sh
+4
@@ -1,6 +1,10 @@
1 #!/bin/sh
2
3 +# a space separated list of UPS names
4 +# if empty, the list returned by 'upsc -l' will be used
5 nut_ups=
6 +
7 +# how frequently to collect UPS data
8 nut_update_every=2
9
10 nut_check() {
charts.d/postfix.chart.sh
+4
@@ -1,6 +1,10 @@
1 #!/bin/sh
2
3 +# the postqueue command
4 +# if empty, it will use the one found in the system path
5 postfix_postqueue=
6 +
7 +# how frequently to collect queue size
8 postfix_update_every=15
9
10 postfix_check() {
charts.d/sensors.chart.sh
+12 -5
@@ -6,12 +6,19 @@
6 # if this chart is called X.chart.sh, then all functions and global variables
7 # must start with X_
8
9 -sensors_sys_dir="/sys/devices"
9 +# the directory the kernel keeps sensor data
10 +sensors_sys_dir="${NETDATA_HOST_PREFIX}/sys/devices"
11 +
12 +# how deep in the tree to check for sensor data
13 sensors_sys_depth=10
14 +
15 +# if set to 1, the script will overwrite internal
16 +# script functions with code generated ones
17 +# leave to 1, is faster
18 sensors_source_update=1
19
13 -# _update_every is a special variable - it holds the number of seconds
14 -# between the calls of the _update() function
20 +# how frequently to collect sensor data
21 +# the default is to collect it at every iteration of charts.d
22 sensors_update_every=
23
24 sensors_find_all_files() {
@@ -160,7 +167,7 @@ sensors_create() {
167 echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.fan_$id \$1\""
168 ;;
169
163 - emergy)
170 + energy)
171 files="$( ls $path/energy*_input 2>/dev/null )"
172 files="$( sensors_check_files $files )"
173 [ -z "$files" ] && continue
@@ -204,7 +211,7 @@ sensors_create() {
211 done
212 done
213
207 - [ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/sensors.sh "}"
214 + [ $sensors_source_update -eq 1 ] && echo >>$TMP_DIR/sensors.sh "}"
215 # cat >&2 $TMP_DIR/sensors.sh
216
217 # ok, load the function sensors_update() we created
charts.d/squid.chart.sh
+41 -9
@@ -1,26 +1,59 @@
1 #!/bin/sh
2
3 -squid_host="127.0.0.1"
4 -squid_port="3128"
5 -squid_url="cache_object://$squid_host:$squid_port/counters"
3 +squid_host=
4 +squid_port=
5 +squid_url=
6 +squid_timeout=2
7 squid_update_every=5
8
8 -squid_get_stats() {
9 - nc $squid_host $squid_port <<EOF
10 -GET $squid_url HTTP/1.0
11 -Host: $squid_host:$squid_port
9 +squid_get_stats_internal() {
10 + local host="$1" port="$2" url="$3"
11 +
12 + nc -w $squid_timeout $host $port <<EOF
13 +GET $url HTTP/1.0
14 +Host: $host:$port
15 Accept: */*
16 User-Agent: netdata (charts.d/squid.chart.sh)
17
18 EOF
19 }
20
21 +squid_get_stats() {
22 + squid_get_stats_internal "$squid_host" "$squid_port" "$squid_url"
23 +}
24 +
25 +squid_autodetect() {
26 + local host="127.0.0.1" port url x
27 +
28 + for port in 3128 8080
29 + do
30 + for url in "cache_object://$host:$port/counters" "/squid-internal-mgr/counters"
31 + do
32 + x=$(squid_get_stats_internal "$host" "$port" "$url" | grep client_http.requests)
33 + if [ ! -z "$x" ]
34 + then
35 + squid_host="$host"
36 + squid_port="$port"
37 + squid_url="$url"
38 + echo >&2 "squid: found squid at '$host:$port' with url '$url'"
39 + return 0
40 + fi
41 + done
42 + done
43 +
44 + echo >&2 "squid: cannot find squid running in localhost. Please set squid_url='url' and squid_host='IP' and squid_port='PORT' in $confd/squid.conf"
45 + return 1
46 +}
47 +
48 squid_check() {
49 require_cmd nc || return 1
50 require_cmd sed || return 1
51 require_cmd egrep || return 1
52
23 - squid_url="cache_object://$squid_host:$squid_port/counters"
53 + if [ -z "$squid_host" -o -z "$squid_port" -o -z "$squid_url" ]
54 + then
55 + squid_autodetect || return 1
56 + fi
57
58 # check once if the url works
59 local x="$(squid_get_stats | grep client_http.requests)"
@@ -109,4 +142,3 @@ VALUESEOF
142
143 return 0
144 }
112 -
plugins.d/charts.d.plugin
+25 -2
@@ -67,6 +67,18 @@ charts_update="_update"
67 charts_check="_check"
68 charts_undescore="_"
69
70 +# when making iterations, charts.d can loop more frequently
71 +# to prevent plugins missing iterations.
72 +# this is a percentage relative to update_every to align its
73 +# iterations.
74 +# The minimum is 10%, the maximum 100%.
75 +# So, if update_every is 1 second and time_divisor is 50,
76 +# charts.d will iterate every 500ms.
77 +# Charts will be called to collect data only if the time
78 +# passes since the last time the collected data is equal or
79 +# above their update_every.
80 +time_divisor=50
81 +
82 # -----------------------------------------------------------------------------
83 # parse parameters
84
@@ -134,6 +146,9 @@ if [ -f "$myconfig" ]
146 echo "DISABLE"
147 exit 1
148 fi
149 + time_divisor=$((time_divisor))
150 + [ $time_divisor -lt 10 ] && time_divisor=10
151 + [ $time_divisor -gt 100 ] && time_divisor=100
152 fi
153
154 if [ "$pause_method" = "suspend" ]
@@ -163,6 +178,7 @@ fi
178
179 # default sleep function
180 loopsleepms() {
181 + [ "$1" = "tellwork" ] && shift
182 sleep $1
183 }
184
@@ -380,6 +396,13 @@ done
396 # -----------------------------------------------------------------------------
397 # update dimensions
398
399 +if [ -z "$run_charts" ]
400 + then
401 + echo >&2 "$PROGRAM_NAME: No charts to collect data from."
402 + echo "DISABLE"
403 + exit 1
404 +fi
405 +
406 declare -A charts_last_update=() charts_min_dt=()
407 global_update() {
408 local exit_after=$((3600 / update_every)) \
@@ -432,10 +455,10 @@ global_update() {
455 if [ "$pause_method" = "suspend" ]
456 then
457 echo "STOPPING_WAKE_ME_UP_PLEASE"
435 - suspend || ( echo >&2 "$PROGRAM_NAME: suspend returned error $?, falling back to sleep."; loopsleepms $debug_time $update_every )
458 + suspend || ( echo >&2 "$PROGRAM_NAME: suspend returned error $?, falling back to sleep."; loopsleepms $debug_time $update_every $time_divisor)
459 else
460 # wait the time you are required to
438 - loopsleepms $debug_time $update_every
461 + loopsleepms $debug_time $update_every $time_divisor
462 fi
463
464 test $c -gt $exit_after && exit 0
plugins.d/loopsleepms.sh.inc
+7 -6
@@ -32,7 +32,7 @@ current_time_ms() {
32 }
33
34 loopsleepms() {
35 - local tellwork=0 t="$1" s m now mstosleep
35 + local tellwork=0 t="$1" div s m now mstosleep
36
37 if [ "$t" = "tellwork" ]
38 then
@@ -40,6 +40,7 @@ loopsleepms() {
40 shift
41 t="$1"
42 fi
43 + div="$2"
44
45 # $t = the time in seconds to wait
46
@@ -56,7 +57,7 @@ loopsleepms() {
57 now="$(( $( $LOOPSLEEP_DATE +'%s * 1000 + %-N / 1000000' ) ))"
58
59 # calculate required sleep in ms
59 - t=$((t * 1000))
60 + t=$((t * 1000 * div / 100))
61
62 # this is our first run
63 # just wait the requested time
@@ -66,18 +67,18 @@ loopsleepms() {
67 LOOPSLEEPMS_LASTWORK=$((now - LOOPSLEEPMS_LASTRUN - LOOPSLEEPMS_LASTSLEEP))
68 # echo "# last loop's work took $LOOPSLEEPMS_LASTWORK ms"
69
69 - test $tellwork -eq 1 && echo >&2 " >>> PERFORMANCE >>> WORK TOOK $LOOPSLEEPMS_LASTWORK ms ( $((LOOPSLEEPMS_LASTWORK * 100 / 1000)).$((LOOPSLEEPMS_LASTWORK % 10))% cpu )"
70 -
70 # calculate ms to sleep
72 - mstosleep=$((t - LOOPSLEEPMS_LASTWORK))
71 + mstosleep=$(( t - LOOPSLEEPMS_LASTWORK ))
72 # echo "# mstosleep is $mstosleep ms"
73
74 # if we are too slow, sleep some time
76 - test $mstosleep -lt $((t / 2)) && mstosleep=$((t / 2))
75 + test $mstosleep -lt 200 && mstosleep=200
76
77 s=$((mstosleep / 1000))
78 m=$((mstosleep - (s * 1000)))
79
80 + test $tellwork -eq 1 && echo >&2 " >>> PERFORMANCE >>> WORK TOOK $LOOPSLEEPMS_LASTWORK ms ( $((LOOPSLEEPMS_LASTWORK * 100 / 1000)).$((LOOPSLEEPMS_LASTWORK % 10))% cpu ) >>> SLEEPING $mstosleep ms"
81 +
82 # echo "# sleeping $s.$m"
83 # echo
84 sleep $s.$m