more fixes related to charts.d
Costa Tsaousis (ktsaou) committed
May 2, 2014 at 16:54 UTC
e6f64cae4ac4f8e3cc307d32996e0cde06d0de73
2 files changed
+131
-7
charts.d/squid-chart.sh
new
+103
@@ -0,0 +1,103 @@
1
+#!/bin/sh
2
+
3
+url="http://127.0.0.1:3128/squid-internal-mgr/counters"
4
+
5
+# report our PID back to netdata
6
+# this is required for netdata to kill this process when it exits
7
+echo "MYPID $$"
8
+
9
+# default sleep function
10
+loopsleepms() {
11
+ sleep $1
12
+}
13
+# if found and included, this file overwrites loopsleepms()
14
+# with a high resolution timer function for precise looping.
15
+. "`dirname $0`/loopsleepms.sh.inc"
16
+
17
+# netdata passes the requested update frequency as the first argument
18
+update_every=$1
19
+update_every=$(( update_every + 1 - 1)) # makes sure it is a number
20
+test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
21
+
22
+# we don't allow more than 1 request every $min seconds
23
+min=1
24
+
25
+# check if there is a config for us - if there is, bring it in
26
+if [ -f "$0.conf" ]
27
+then
28
+ . "$0.conf"
29
+fi
30
+
31
+# make sure we respect the $min update frequency
32
+test $update_every -lt $min && update_every=$min
33
+
34
+# check once if the url works
35
+wget 2>/dev/null -O /dev/null "$url"
36
+if [ ! $? -eq 0 ]
37
+then
38
+ # it does not work - disable the plugin
39
+ echo "DISABLE"
40
+ exit 1
41
+fi
42
+
43
+# create the charts
44
+cat <<EOF
45
+CHART squid.client_bandwidth '' "Squid Client Bandwidth" "kilobits/s" squid squid area 1 $update_every
46
+DIMENSION client_http_kbytes_in in incremental 8 1
47
+DIMENSION client_http_kbytes_out out incremental -8 1
48
+DIMENSION client_http_hit_kbytes_out hits incremental -8 1
49
+
50
+CHART squid.client_requests '' "Squid Client Requests" "requests/s" squid squid line 3 $update_every
51
+DIMENSION client_http_requests requests incremental 1 1
52
+DIMENSION client_http_hits hits incremental 1 1
53
+DIMENSION client_http_errors errors incremental -1 1
54
+
55
+CHART squid.server_bandwidth '' "Squid Server Bandwidth" "kilobits/s" squid squid area 2 $update_every
56
+DIMENSION server_all_kbytes_in in incremental 8 1
57
+DIMENSION server_all_kbytes_out out incremental -8 1
58
+
59
+CHART squid.server_requests '' "Squid Server Requests" "requests/s" squid squid line 4 $update_every
60
+DIMENSION server_all_requests requests incremental 1 1
61
+DIMENSION server_all_errors errors incremental -1 1
62
+EOF
63
+
64
+# You can create more charts if you like.
65
+# Just add more chart definitions.
66
+
67
+# work forever
68
+while [ 1 ]
69
+do
70
+ # do all the work to collect / calculate the values
71
+ # for each dimension
72
+
73
+ # get the values from squid
74
+ eval `wget 2>/dev/null -O - "$url" | sed -e "s/\./_/g" -e "s/ = /=/g" | egrep "(^client_http_|^server_all_)"`
75
+
76
+ # write the result of the work.
77
+ cat <<VALUESEOF
78
+BEGIN squid.client_bandwidth
79
+SET client_http_kbytes_in = $client_http_kbytes_in
80
+SET client_http_kbytes_out = $client_http_kbytes_out
81
+SET client_http_hit_kbytes_out = $client_http_hit_kbytes_out
82
+END
83
+
84
+BEGIN squid.client_requests
85
+SET client_http_requests = $client_http_requests
86
+SET client_http_hits = $client_http_hits
87
+SET client_http_errors = $client_http_errors
88
+END
89
+
90
+BEGIN squid.server_bandwidth
91
+SET server_all_kbytes_in = $server_all_kbytes_in
92
+SET server_all_kbytes_out = $server_all_kbytes_out
93
+END
94
+
95
+BEGIN squid.server_requests
96
+SET server_all_requests = $server_all_requests
97
+SET server_all_errors = $server_all_errors
98
+END
99
+VALUESEOF
100
+
101
+ # wait the time you are required to
102
+ loopsleepms $update_every
103
+done
netdata.c
+28
-7
@@ -5239,7 +5239,9 @@ void tc_device_commit(struct tc_device *d)
5239
5240
if(strcmp(d->id, d->name) != 0) {
5241
// update the device name with the new one
5242
- rrd_stats_set_name(st, d->name);
5242
+ char buf[RRD_STATS_NAME_MAX + 1];
5243
+ snprintf(buf, RRD_STATS_NAME_MAX, "%s.%s", st->type, d->name);
5244
+ rrd_stats_set_name(st, buf);
5245
}
5246
}
5247
@@ -5520,6 +5522,8 @@ struct chartd {
5522
char fullfilename[FILENAME_MAX+1]; // with path
5523
char cmd[CHARTSD_CMD_MAX+1]; // the command that is executes
5524
5525
+ char config_name[CONFIG_MAX_NAME + 1];
5526
+
5527
pid_t pid;
5528
pthread_t thread;
5529
@@ -5586,7 +5590,9 @@ void *chartsd_worker_thread(void *arg)
5590
5591
unsigned long long count = 0;
5592
while(fgets(line, CHARTSD_LINE_MAX, fp) != NULL) {
5589
- char *p = line;
5593
+ char *p = trim(line);
5594
+ debug(D_CHARTSD, "CHARTSD: %s: %s", cd->filename, line);
5595
+
5596
char *s = qstrsep(&p);
5597
5598
if(!s || !*s) continue;
@@ -5740,12 +5746,24 @@ void *chartsd_worker_thread(void *arg)
5746
cd->pid = atol(pid);
5747
debug(D_CHARTSD, "CHARTSD: %s is on pid %d", cd->id, cd->pid);
5748
}
5749
+ else if(!strcmp(s, "DISABLE")) {
5750
+ error("CHARTSD: script '%s' called DISABLE. Disabling it.", cd->fullfilename);
5751
+ config_set_boolean("plugin:charts.d", cd->config_name, 0);
5752
+ break;
5753
+ }
5754
else error("CHARTSD: script %s is sending command '%s' which is not known by netdata", cd->fullfilename, s);
5755
}
5745
- if(!count) error("Script '%s' does not generate usefull output.", cd->fullfilename);
5756
+
5757
+ // fgets() failed or loop broke
5758
pclose(fp);
5759
5748
- sleep(cd->update_every);
5760
+ if(!count) {
5761
+ error("CHARTSD: script '%s' does not generate usefull output. Disabling it.", cd->fullfilename);
5762
+ config_set_boolean("plugin:charts.d", cd->config_name, 0);
5763
+ }
5764
+
5765
+ if(config_get_boolean("plugin:charts.d", cd->config_name, 1)) sleep(cd->update_every);
5766
+ else break;
5767
}
5768
5769
cd->obsolete = 1;
@@ -5778,9 +5796,9 @@ void *chartsd_main(void *ptr)
5796
continue;
5797
}
5798
5781
- char buf[CONFIG_MAX_NAME + 1];
5782
- snprintf(buf, CONFIG_MAX_NAME, "plugin %.*s", (int)(len - CHARTS_D_FILE_SUFFIX_LEN), file->d_name);
5783
- if(!config_get_boolean("plugin:charts.d", buf, 1)) continue;
5799
+ char varname[CONFIG_MAX_NAME + 1];
5800
+ snprintf(varname, CONFIG_MAX_NAME, "plugin %.*s", (int)(len - CHARTS_D_FILE_SUFFIX_LEN), file->d_name);
5801
+ if(!config_get_boolean("plugin:charts.d", varname, 1)) continue;
5802
5803
// check if it runs already
5804
for(cd = chartsd_root ; cd ; cd = cd->next) {
@@ -5800,6 +5818,9 @@ void *chartsd_main(void *ptr)
5818
// link it
5819
if(chartsd_root) cd->next = chartsd_root;
5820
chartsd_root = cd;
5821
+
5822
+ // copy its config name
5823
+ strncpy(cd->config_name, varname, CONFIG_MAX_NAME);
5824
}
5825
5826
strncpy(cd->filename, file->d_name, FILENAME_MAX);