supports for charts.d scripts and plugins.d plugins
Costa Tsaousis (ktsaou) committed
May 3, 2014 at 20:10 UTC
daade62d36bdb45081ac5cf48296d1e471006cdc
4 files changed
+139
-169
charts.d/example.chart.sh
+12
-43
@@ -1,52 +1,29 @@
1
#!/bin/sh
2
3
-# report our PID back to netdata
4
-# this is required for netdata to kill this process when it exits
5
-echo "MYPID $$"
3
+example_check() {
4
+ # this should return:
5
+ # - 0 to enable the chart
6
+ # - 1 to disable the chart
7
7
-# default sleep function
8
-loopsleepms() {
9
- sleep $1
8
+ return 0
9
}
11
-# if found and included, this file overwrites loopsleepms()
12
-# with a high resolution timer function for precise looping.
13
-. "`dirname $0`/loopsleepms.sh.inc"
14
-
15
-# netdata passes the requested update frequency as the first argument
16
-update_every=$1
17
-update_every=$(( update_every + 1 - 1)) # makes sure it is a number
18
-test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
19
-
10
11
+example_create() {
12
# create the chart with 3 dimensions
13
cat <<EOF
23
-CHART example.load '' "System Load Average" "load" load load line 500 $update_every
24
-DIMENSION load1 '1 min' absolute 1 100
25
-DIMENSION load5 '5 mins' absolute 1 100
26
-DIMENSION load15 '15 mins' absolute 1 100
27
-
14
CHART example.random '' "Random Numbers Stacked Chart" "% of random numbers" random random stacked 5000 $update_every
15
DIMENSION random1 '' percentage-of-absolute-row 1 1
16
DIMENSION random2 '' percentage-of-absolute-row 1 1
17
DIMENSION random3 '' percentage-of-absolute-row 1 1
18
EOF
19
34
-# You can create more charts if you like.
35
-# Just add more chart definitions.
20
+ return 0
21
+}
22
37
-# work forever
38
-while [ 1 ]
39
-do
23
+example_update() {
24
# do all the work to collect / calculate the values
25
# for each dimension
42
-
43
- # here we parse the system average load
44
- # it is decimal (with 2 decimal digits), so we remove the dot and
45
- # at the definition we have divisor = 100, to have the graph show the right value
46
- loadavg="`cat /proc/loadavg | sed -e "s/\.//g"`"
47
- load1=`echo $loadavg | cut -d ' ' -f 1`
48
- load5=`echo $loadavg | cut -d ' ' -f 2`
49
- load15=`echo $loadavg | cut -d ' ' -f 3`
26
+ # remember: KEEP IT SIMPLE AND SHORT
27
28
value1=$RANDOM
29
value2=$RANDOM
@@ -54,12 +31,6 @@ do
31
32
# write the result of the work.
33
cat <<VALUESEOF
57
-BEGIN example.load
58
-SET load1 = $load1
59
-SET load5 = $load5
60
-SET load15 = $load15
61
-END
62
-
34
BEGIN example.random
35
SET random1 = $value1
36
SET random2 = $value2
@@ -67,8 +38,6 @@ SET random3 = $value3
38
END
39
VALUESEOF
40
70
- # if you have more charts, add BEGIN->END statements here
41
+ return 0
42
+}
43
72
- # wait the time you are required to
73
- loopsleepms $update_every
74
-done
charts.d/squid.chart.sh
+24
-44
@@ -1,41 +1,22 @@
1
#!/bin/sh
2
3
-url="http://127.0.0.1:8080/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
3
+squid_url="http://127.0.0.1:8080/squid-internal-mgr/counters"
4
+
5
+squid_check() {
6
+ # check once if the url works
7
+ wget 2>/dev/null -O /dev/null "$squid_url"
8
+ if [ ! $? -eq 0 ]
9
+ then
10
+ echo >&2 "squid: cannot fetch the url: $squid_url. Please set squid_url='url' in $confd/squid.conf"
11
+ return 1
12
+ fi
13
+
14
+ return 0
15
}
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 accept a url as the second argument
23
-if [ ! -z "$2" ]
24
-then
25
- url="$2"
26
-fi
27
-
28
-# check once if the url works
29
-wget 2>/dev/null -O /dev/null "$url"
30
-if [ ! $? -eq 0 ]
31
-then
32
- # it does not work - disable the plugin
33
- echo "DISABLE"
34
- exit 1
35
-fi
36
-
37
-# create the charts
38
-cat <<EOF
16
+
17
+squid_create() {
18
+ # create the charts
19
+ cat <<EOF
20
CHART squid.client_bandwidth '' "Squid Client Bandwidth" "kilobits/s" squid squid area 1 $update_every
21
DIMENSION client_http_kbytes_in in incremental 8 1
22
DIMENSION client_http_kbytes_out out incremental -8 1
@@ -54,18 +35,17 @@ CHART squid.server_requests '' "Squid Server Requests" "requests/s" squid squid
35
DIMENSION server_all_requests requests incremental 1 1
36
DIMENSION server_all_errors errors incremental -1 1
37
EOF
38
+
39
+ return 0
40
+}
41
58
-# You can create more charts if you like.
59
-# Just add more chart definitions.
42
61
-# work forever
62
-while [ 1 ]
63
-do
43
+squid_update() {
44
# do all the work to collect / calculate the values
45
# for each dimension
46
47
# get the values from squid
68
- eval `wget 2>/dev/null -O - "$url" | sed -e "s/\./_/g" -e "s/ = /=/g" | egrep "(^client_http_|^server_all_)"`
48
+ eval `wget 2>/dev/null -O - "$squid_url" | sed -e "s/\./_/g" -e "s/ = /=/g" | egrep "(^client_http_|^server_all_)"`
49
50
# write the result of the work.
51
cat <<VALUESEOF
@@ -92,6 +72,6 @@ SET server_all_errors = $server_all_errors
72
END
73
VALUESEOF
74
95
- # wait the time you are required to
96
- loopsleepms $update_every
97
-done
75
+ return 0
76
+}
77
+
netdata.c
+89
-68
@@ -87,7 +87,7 @@
87
#define D_TC_LOOP 0x00000100
88
#define D_DEFLATE 0x00000200
89
#define D_CONFIG 0x00000400
90
-#define D_CHARTSD 0x00000800
90
+#define D_PLUGINSD 0x00000800
91
#define D_CHILDS 0x00001000
92
93
#define CT_APPLICATION_JSON 1
@@ -319,7 +319,7 @@ FILE *mypopen(const char *command, pid_t *pidptr)
319
close(pipefd[PIPE_WRITE]);
320
}
321
322
- debug(D_CHILDS, "Running command: '%s'\n", command);
322
+ fprintf(stderr, "executing command: '%s'\n", command);
323
execl("/bin/sh", "sh", "-c", command, NULL);
324
exit(1);
325
}
@@ -441,7 +441,7 @@ int create_listen_socket(int port)
441
442
#define CONFIG_MAX_NAME 1024
443
#define CONFIG_MAX_VALUE 1024
444
-#define CONFIG_FILENAME "netdata.conf"
444
+#define CONFIG_FILENAME "conf.d/netdata.conf"
445
#define CONFIG_FILE_LINE_MAX 4096
446
447
pthread_mutex_t config_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -2100,11 +2100,14 @@ void generate_config(struct web_buffer *wb, int only_changed)
2100
if(i == pri) {
2101
int used = 0;
2102
int changed = 0;
2103
+ int count = 0;
2104
for(cv = co->values; cv ; cv = cv->next) {
2105
used += cv->used;
2106
changed += cv->changed;
2107
+ count++;
2108
}
2109
2110
+ if(!count) continue;
2111
if(only_changed && !changed) continue;
2112
2113
if(!used) {
@@ -5227,7 +5230,7 @@ void *proc_main(void *ptr)
5230
5231
// ----------------------------------------------------------------------------
5232
// /sbin/tc processor
5230
-// this requires the script charts.d/tc-qos-collector.sh
5233
+// this requires the script plugins.d/tc-qos-helper.sh
5234
5235
#define TC_LINE_MAX 1024
5236
@@ -5429,7 +5432,7 @@ void *tc_main(void *ptr)
5432
struct tc_device *device = NULL;
5433
struct tc_class *class = NULL;
5434
5432
- snprintf(buffer, TC_LINE_MAX, "exec %s %d", config_get("plugin:tc", "script to run to get tc values", "charts.d/tc-qos-collector.sh"), update_every);
5435
+ snprintf(buffer, TC_LINE_MAX, "exec %s %d", config_get("plugin:tc", "script to run to get tc values", "plugins.d/tc-qos-helper.sh"), update_every);
5436
debug(D_TC_LOOP, "executing '%s'", buffer);
5437
// fp = popen(buffer, "r");
5438
fp = mypopen(buffer, &tc_child_pid);
@@ -5520,7 +5523,11 @@ void *tc_main(void *ptr)
5523
}
5524
else if((strcmp(p, "MYPID") == 0)) {
5525
char *id = strsep(&b, " \n");
5523
- tc_child_pid = atol(id);
5526
+ pid_t pid = atol(id);
5527
+
5528
+ if(pid != tc_child_pid)
5529
+ error("tc-qos-helper reports wrong pid %d (expected %d).", pid, tc_child_pid);
5530
+
5531
debug(D_TC_LOOP, "TC: Child PID is %d.", tc_child_pid);
5532
}
5533
}
@@ -5585,19 +5592,19 @@ void *cpuidlejitter_main(void *ptr)
5592
}
5593
5594
// ----------------------------------------------------------------------------
5588
-// charts.d
5595
+// plugins.d
5596
5590
-#define CHARTS_D_FILE_SUFFIX "-chart.sh"
5591
-#define CHARTS_D_FILE_SUFFIX_LEN strlen(CHARTS_D_FILE_SUFFIX)
5592
-#define CHARTSD_CMD_MAX (FILENAME_MAX*2)
5593
-#define CHARTSD_LINE_MAX 1024
5597
+#define PLUGINSD_FILE_SUFFIX ".plugin"
5598
+#define PLUGINSD_FILE_SUFFIX_LEN strlen(PLUGINSD_FILE_SUFFIX)
5599
+#define PLUGINSD_CMD_MAX (FILENAME_MAX*2)
5600
+#define PLUGINSD_LINE_MAX 1024
5601
5602
struct chartd {
5603
char id[CONFIG_MAX_NAME+1]; // config node id
5604
5605
char filename[FILENAME_MAX+1]; // just the filename
5606
char fullfilename[FILENAME_MAX+1]; // with path
5600
- char cmd[CHARTSD_CMD_MAX+1]; // the command that is executes
5607
+ char cmd[PLUGINSD_CMD_MAX+1]; // the command that is executes
5608
5609
pid_t pid;
5610
pthread_t thread;
@@ -5607,7 +5614,7 @@ struct chartd {
5614
int enabled;
5615
5616
struct chartd *next;
5610
-} *chartsd_root = NULL;
5617
+} *pluginsd_root = NULL;
5618
5619
// like strsep() but:
5620
// it trims spaces before and after each value
@@ -5647,10 +5654,10 @@ char *qstrsep(char **ptr)
5654
return s;
5655
}
5656
5650
-void *chartsd_worker_thread(void *arg)
5657
+void *pluginsd_worker_thread(void *arg)
5658
{
5659
struct chartd *cd = (struct chartd *)arg;
5653
- char line[CHARTSD_LINE_MAX + 1];
5660
+ char line[PLUGINSD_LINE_MAX + 1];
5661
5662
while(1) {
5663
// FILE *fp = popen(cd->cmd, "r");
@@ -5663,9 +5670,9 @@ void *chartsd_worker_thread(void *arg)
5670
RRD_STATS *st = NULL;
5671
5672
unsigned long long count = 0;
5666
- while(fgets(line, CHARTSD_LINE_MAX, fp) != NULL) {
5673
+ while(fgets(line, PLUGINSD_LINE_MAX, fp) != NULL) {
5674
char *p = trim(line);
5668
- debug(D_CHARTSD, "CHARTSD: %s: %s", cd->filename, line);
5675
+ debug(D_PLUGINSD, "PLUGINSD: %s: %s", cd->filename, line);
5676
5677
char *s = qstrsep(&p);
5678
@@ -5676,16 +5683,16 @@ void *chartsd_worker_thread(void *arg)
5683
char *value = qstrsep(&p);
5684
5685
if(!dimension || !equal || *equal != '=' || !value) {
5679
- error("CHARTSD: script %s is requesting a SET on chart '%s', like this: 'SET %s %s %s %s'", cd->fullfilename, st->id, dimension?dimension:"", equal?equal:"", value?value:"");
5686
+ error("PLUGINSD: script %s is requesting a SET on chart '%s', like this: 'SET %s %s %s %s'", cd->fullfilename, st->id, dimension?dimension:"", equal?equal:"", value?value:"");
5687
continue;
5688
}
5689
5690
if(!st) {
5684
- error("CHARTSD: script %s is requesting a SET, without a BEGIN", cd->fullfilename);
5691
+ error("PLUGINSD: script %s is requesting a SET, without a BEGIN", cd->fullfilename);
5692
continue;
5693
}
5694
5688
- if(st->debug) debug(D_CHARTSD, "CHARTSD: script %s is setting dimension %s/%s to %s", cd->fullfilename, st->id, dimension, value);
5695
+ if(st->debug) debug(D_PLUGINSD, "PLUGINSD: script %s is setting dimension %s/%s to %s", cd->fullfilename, st->id, dimension, value);
5696
rrd_stats_dimension_set(st, dimension, atoll(value));
5697
5698
count++;
@@ -5693,24 +5700,24 @@ void *chartsd_worker_thread(void *arg)
5700
else if(!strcmp(s, "BEGIN")) {
5701
char *id = qstrsep(&p);
5702
if(!id) {
5696
- error("CHARTSD: script %s is requesting a BEGIN without a chart id", cd->fullfilename);
5703
+ error("PLUGINSD: script %s is requesting a BEGIN without a chart id", cd->fullfilename);
5704
continue;
5705
}
5706
5707
st = rrd_stats_find(id);
5708
if(!st) {
5702
- error("CHARTSD: script %s is requesting a BEGIN on chart '%s', which does not exist", cd->fullfilename, id);
5709
+ error("PLUGINSD: script %s is requesting a BEGIN on chart '%s', which does not exist", cd->fullfilename, id);
5710
continue;
5711
}
5712
if(st->counter) rrd_stats_next(st);
5713
}
5714
else if(!strcmp(s, "END")) {
5715
if(!st) {
5709
- error("CHARTSD: script %s is requesting an END, without a BEGIN", cd->fullfilename);
5716
+ error("PLUGINSD: script %s is requesting an END, without a BEGIN", cd->fullfilename);
5717
continue;
5718
}
5719
5713
- if(st->debug) debug(D_CHARTSD, "CHARTSD: script %s is requesting a END on chart %s", cd->fullfilename, st->id);
5720
+ if(st->debug) debug(D_PLUGINSD, "PLUGINSD: script %s is requesting a END on chart %s", cd->fullfilename, st->id);
5721
rrd_stats_done(st);
5722
st = NULL;
5723
}
@@ -5733,7 +5740,7 @@ void *chartsd_worker_thread(void *arg)
5740
char *update_every_s = qstrsep(&p);
5741
5742
if(!type || !*type || !id || !*id) {
5736
- error("CHARTSD: script %s is requesting a CHART, without a type.id", cd->fullfilename);
5743
+ error("PLUGINSD: script %s is requesting a CHART, without a type.id", cd->fullfilename);
5744
continue;
5745
}
5746
@@ -5753,7 +5760,7 @@ void *chartsd_worker_thread(void *arg)
5760
5761
st = rrd_stats_find_bytype(type, id);
5762
if(!st) {
5756
- debug(D_CHARTSD, "CHARTSD: Creating chart type='%s', id='%s', name='%s', family='%s', category='%s', chart='%s', priority=%d, update_every=%d"
5763
+ debug(D_PLUGINSD, "PLUGINSD: Creating chart type='%s', id='%s', name='%s', family='%s', category='%s', chart='%s', priority=%d, update_every=%d"
5764
, type, id
5765
, name?name:""
5766
, family?family:""
@@ -5768,7 +5775,7 @@ void *chartsd_worker_thread(void *arg)
5775
5776
if(strcmp(category, "none") == 0) st->isdetail = 1;
5777
}
5771
- else debug(D_CHARTSD, "CHARTSD: Chart '%s' already exists. Not adding it again.", st->id);
5778
+ else debug(D_PLUGINSD, "PLUGINSD: Chart '%s' already exists. Not adding it again.", st->id);
5779
}
5780
else if(!strcmp(s, "DIMENSION")) {
5781
char *id = qstrsep(&p);
@@ -5779,12 +5786,12 @@ void *chartsd_worker_thread(void *arg)
5786
char *hidden = qstrsep(&p);
5787
5788
if(!id || !*id) {
5782
- error("CHARTSD: script %s is requesting a DIMENSION, without an id", cd->fullfilename);
5789
+ error("PLUGINSD: script %s is requesting a DIMENSION, without an id", cd->fullfilename);
5790
continue;
5791
}
5792
5793
if(!st) {
5787
- error("CHARTSD: script %s is requesting a DIMENSION, without a CHART", cd->fullfilename);
5794
+ error("PLUGINSD: script %s is requesting a DIMENSION, without a CHART", cd->fullfilename);
5795
continue;
5796
}
5797
@@ -5798,7 +5805,7 @@ void *chartsd_worker_thread(void *arg)
5805
5806
if(!algorithm || !*algorithm) algorithm = "absolute";
5807
5801
- if(st->debug) debug(D_CHARTSD, "CHARTSD: Creating dimension in chart %s, id='%s', name='%s', algorithm='%s', multiplier=%ld, divisor=%ld, hidden='%s'"
5808
+ if(st->debug) debug(D_PLUGINSD, "PLUGINSD: Creating dimension in chart %s, id='%s', name='%s', algorithm='%s', multiplier=%ld, divisor=%ld, hidden='%s'"
5809
, st->id
5810
, id
5811
, name?name:""
@@ -5813,26 +5820,30 @@ void *chartsd_worker_thread(void *arg)
5820
rd = rrd_stats_dimension_add(st, id, name, multiplier, divisor, algorithm_id(algorithm));
5821
if(hidden && strcmp(hidden, "hidden") == 0) rd->hidden = 1;
5822
}
5816
- else if(st->debug) debug(D_CHARTSD, "CHARTSD: dimension %s/%s already exists. Not adding it again.", st->id, id);
5823
+ else if(st->debug) debug(D_PLUGINSD, "PLUGINSD: dimension %s/%s already exists. Not adding it again.", st->id, id);
5824
}
5825
else if(!strcmp(s, "MYPID")) {
5819
- char *pid = qstrsep(&p);
5820
- cd->pid = atol(pid);
5821
- debug(D_CHARTSD, "CHARTSD: %s is on pid %d", cd->id, cd->pid);
5826
+ char *pid_s = qstrsep(&p);
5827
+ pid_t pid = atol(pid_s);
5828
+
5829
+ if(pid != cd->pid)
5830
+ error("plugin %s reports wrong pid %d (expected %d).", cd->filename, pid, cd->pid);
5831
+
5832
+ debug(D_PLUGINSD, "PLUGINSD: %s is on pid %d", cd->id, cd->pid);
5833
}
5834
else if(!strcmp(s, "DISABLE")) {
5824
- error("CHARTSD: script '%s' called DISABLE. Disabling it.", cd->fullfilename);
5835
+ error("PLUGINSD: script '%s' called DISABLE. Disabling it.", cd->fullfilename);
5836
cd->enabled = 0;
5837
break;
5838
}
5828
- else error("CHARTSD: script %s is sending command '%s' which is not known by netdata", cd->fullfilename, s);
5839
+ else error("PLUGINSD: script %s is sending command '%s' which is not known by netdata", cd->fullfilename, s);
5840
}
5841
5842
// fgets() failed or loop broke
5843
mypclose(fp);
5844
5845
if(!count && cd->enabled) {
5835
- error("CHARTSD: script '%s' does not generate usefull output. Disabling it.", cd->fullfilename);
5846
+ error("PLUGINSD: script '%s' does not generate usefull output. Disabling it.", cd->fullfilename);
5847
cd->enabled = 0;
5848
}
5849
@@ -5844,15 +5855,18 @@ void *chartsd_worker_thread(void *arg)
5855
return NULL;
5856
}
5857
5847
-void *chartsd_main(void *ptr)
5858
+void *pluginsd_main(void *ptr)
5859
{
5860
if(ptr) { ; }
5850
- char *dir_name = config_get("plugin:charts.d", "charts.d directory", "charts.d");
5851
- int automatic_run = config_get_boolean("plugin:charts.d", "enable runnig new scripts", 0);
5861
+ char *dir_name = config_get("plugins", "plugins directory", "plugins.d");
5862
+ int automatic_run = config_get_boolean("plugins", "enable running new plugins", 0);
5863
+ int scan_frequency = config_get_number("plugins", "check for new plugins every", 60);
5864
DIR *dir = NULL;
5865
struct dirent *file = NULL;
5866
struct chartd *cd;
5867
5868
+ if(scan_frequency < 1) scan_frequency = 1;
5869
+
5870
while(1) {
5871
dir = opendir(dir_name);
5872
if(!dir) {
@@ -5861,23 +5875,32 @@ void *chartsd_main(void *ptr)
5875
}
5876
5877
while((file = readdir(dir))) {
5864
- debug(D_CHARTSD, "CHARTSD: Examining file '%s'", file->d_name);
5878
+ debug(D_PLUGINSD, "PLUGINSD: Examining file '%s'", file->d_name);
5879
5880
if(strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0) continue;
5881
5882
int len = strlen(file->d_name);
5869
- if(len <= (int)CHARTS_D_FILE_SUFFIX_LEN) continue;
5870
- if(strcmp(CHARTS_D_FILE_SUFFIX, &file->d_name[len - CHARTS_D_FILE_SUFFIX_LEN]) != 0) {
5871
- debug(D_CHARTSD, "CHARTSD: File '%s' does not end in '%s'.", file->d_name, CHARTS_D_FILE_SUFFIX);
5883
+ if(len <= (int)PLUGINSD_FILE_SUFFIX_LEN) continue;
5884
+ if(strcmp(PLUGINSD_FILE_SUFFIX, &file->d_name[len - PLUGINSD_FILE_SUFFIX_LEN]) != 0) {
5885
+ debug(D_PLUGINSD, "PLUGINSD: File '%s' does not end in '%s'.", file->d_name, PLUGINSD_FILE_SUFFIX);
5886
+ continue;
5887
+ }
5888
+
5889
+ char pluginname[CONFIG_MAX_NAME + 1];
5890
+ snprintf(pluginname, CONFIG_MAX_NAME, "%.*s", (int)(len - PLUGINSD_FILE_SUFFIX_LEN), file->d_name);
5891
+ int enabled = config_get_boolean("plugins", pluginname, automatic_run);
5892
+
5893
+ if(!enabled) {
5894
+ debug(D_PLUGINSD, "PLUGINSD: plugin '%s' is not enabled", file->d_name);
5895
continue;
5896
}
5897
5898
// check if it runs already
5876
- for(cd = chartsd_root ; cd ; cd = cd->next) {
5899
+ for(cd = pluginsd_root ; cd ; cd = cd->next) {
5900
if(strcmp(cd->filename, file->d_name) == 0) break;
5901
}
5902
if(cd && !cd->obsolete) {
5880
- debug(D_CHARTSD, "CHARTSD: %s is already running", cd->filename);
5903
+ debug(D_PLUGINSD, "PLUGINSD: plugin '%s' is already running", cd->filename);
5904
continue;
5905
}
5906
@@ -5887,25 +5910,25 @@ void *chartsd_main(void *ptr)
5910
cd = calloc(sizeof(struct chartd), 1);
5911
if(!cd) fatal("Cannot allocate memory for chart.d");
5912
5890
- snprintf(cd->id, CONFIG_MAX_NAME, "plugin:charts.d:%.*s", (int)(len - CHARTS_D_FILE_SUFFIX_LEN), file->d_name);
5913
+ snprintf(cd->id, CONFIG_MAX_NAME, "plugin:%s", pluginname);
5914
5915
strncpy(cd->filename, file->d_name, FILENAME_MAX);
5916
snprintf(cd->fullfilename, FILENAME_MAX, "%s/%s", dir_name, cd->filename);
5917
5895
- cd->enabled = config_get_boolean(cd->id, "enable", automatic_run);
5918
+ cd->enabled = enabled;
5919
cd->update_every = config_get_number(cd->id, "update every", update_every);
5897
- snprintf(cd->cmd, CHARTSD_CMD_MAX, "exec %s %d %s", cd->fullfilename, cd->update_every, config_get(cd->id, "more command options", ""));
5920
+ snprintf(cd->cmd, PLUGINSD_CMD_MAX, "exec %s %d %s", cd->fullfilename, cd->update_every, config_get(cd->id, "command options", ""));
5921
5922
// link it
5900
- if(chartsd_root) cd->next = chartsd_root;
5901
- chartsd_root = cd;
5923
+ if(pluginsd_root) cd->next = pluginsd_root;
5924
+ pluginsd_root = cd;
5925
}
5926
cd->obsolete = 0;
5927
5928
if(!cd->enabled) continue;
5929
5930
// spawn a new thread for it
5908
- if(pthread_create(&cd->thread, NULL, chartsd_worker_thread, cd) != 0) {
5931
+ if(pthread_create(&cd->thread, NULL, pluginsd_worker_thread, cd) != 0) {
5932
error("CHARTS.D: failed to create new thread for chart.d %s.", cd->filename);
5933
cd->obsolete = 1;
5934
}
@@ -5914,7 +5937,7 @@ void *chartsd_main(void *ptr)
5937
}
5938
5939
closedir(dir);
5917
- sleep(60);
5940
+ sleep(scan_frequency);
5941
}
5942
5943
return NULL;
@@ -5930,7 +5953,7 @@ void kill_childs()
5953
tc_child_pid = 0;
5954
5955
struct chartd *cd;
5933
- for(cd = chartsd_root ; cd ; cd = cd->next)
5956
+ for(cd = pluginsd_root ; cd ; cd = cd->next)
5957
if(cd->pid && !cd->obsolete) {
5958
kill(cd->pid, SIGTERM);
5959
cd->pid = 0;
@@ -6237,14 +6260,14 @@ int main(int argc, char **argv)
6260
6261
// --------------------------------------------------------------------
6262
6240
- sprintf(buffer, "0x%08llx", debug_flags);
6263
+ sprintf(buffer, "0x%08llx", 0ULL);
6264
char *flags = config_get("global", "debug flags", buffer);
6265
debug_flags = strtoull(flags, NULL, 0);
6266
debug(D_OPTIONS, "Debug flags set to '0x%8llx'.", debug_flags);
6267
6268
// --------------------------------------------------------------------
6269
6247
- output_log_file = config_get("global", "debug log", "none");
6270
+ output_log_file = config_get("global", "debug log", "log/debug.log");
6271
if(strcmp(output_log_file, "syslog") == 0) {
6272
output_log_syslog = 1;
6273
output_log_file = NULL;
@@ -6258,7 +6281,7 @@ int main(int argc, char **argv)
6281
// --------------------------------------------------------------------
6282
6283
silent = 0;
6261
- error_log_file = config_get("global", "error log", "syslog");
6284
+ error_log_file = config_get("global", "error log", "log/error.log");
6285
if(strcmp(error_log_file, "syslog") == 0) {
6286
error_log_syslog = 1;
6287
error_log_file = NULL;
@@ -6272,7 +6295,7 @@ int main(int argc, char **argv)
6295
6296
// --------------------------------------------------------------------
6297
6275
- access_log_file = config_get("global", "access log", "syslog");
6298
+ access_log_file = config_get("global", "access log", "log/access.log");
6299
if(strcmp(access_log_file, "syslog") == 0) {
6300
access_log_syslog = 1;
6301
access_log_file = NULL;
@@ -6348,10 +6371,10 @@ int main(int argc, char **argv)
6371
}
6372
6373
6351
- if(output_log_syslog || error_log_syslog || access_log_syslog) {
6374
+ if(output_log_syslog || error_log_syslog || access_log_syslog)
6375
openlog("netdata", LOG_PID, LOG_DAEMON);
6353
- syslog(LOG_NOTICE, "netdata started.");
6354
- }
6376
+
6377
+ error("NetData started on pid %d", getpid());
6378
6379
// make sure we cleanup correctly
6380
atexit(bye);
@@ -6360,7 +6383,7 @@ int main(int argc, char **argv)
6383
for (i = 1 ; i < 65 ;i++) if(i != SIGSEGV) signal(i, sig_handler);
6384
6385
6363
- pthread_t p_proc, p_tc, p_jitter, p_chartsd;
6386
+ pthread_t p_proc, p_tc, p_jitter, p_pluginsd;
6387
6388
// spawn childs to collect data
6389
if(config_get_boolean("plugins", "tc", 1)) {
@@ -6384,12 +6407,10 @@ int main(int argc, char **argv)
6407
error("Cannot request detach of newly created proc thread.");
6408
}
6409
6387
- if(config_get_boolean("plugins", "charts.d", 1)) {
6388
- if(pthread_create(&p_chartsd, NULL, chartsd_main, NULL))
6389
- error("failed to create new thread for charts.d.");
6390
- else if(pthread_detach(p_chartsd))
6391
- error("Cannot request detach of newly created charts.d thread.");
6392
- }
6410
+ if(pthread_create(&p_pluginsd, NULL, pluginsd_main, NULL))
6411
+ error("failed to create new thread for plugins.d.");
6412
+ else if(pthread_detach(p_pluginsd))
6413
+ error("Cannot request detach of newly created plugins.d thread.");
6414
6415
// the main process - the web server listener
6416
// this never ends
netdata.start
+14
-14
@@ -27,9 +27,9 @@ NETDATA_CONFIG_PORT=19999
27
# our web files
28
NETDATA_CONFIG_WEB_DIR=web
29
30
-if [ -f netdata.conf ]
30
+if [ -f conf.d/netdata.conf ]
31
then
32
- x="`grep "\[global\]" netdata.conf`"
32
+ x="`grep "\[global\]" conf.d/netdata.conf`"
33
if [ -z "$x" ]
34
then
35
# import the old values
@@ -38,10 +38,10 @@ then
38
rm netdata.conf.tmp
39
40
mv netdata.conf netdata.conf.old
41
- echo "You are having an old config. Moved to netdata.conf.old"
41
+ echo "You are having an old config. Moved to netdata.conf.old. New config is in conf.d/"
42
else
43
# find if debug is enabled in the config
44
- df=`grep -C 3 "\[debug\]" netdata.conf | grep "flags" | tail -n 1 | cut -d '=' -f 2 | sed s"/ //g"`
44
+ df=`grep -C 3 "\[debug\]" conf.d/netdata.conf | grep "flags" | tail -n 1 | cut -d '=' -f 2 | sed s"/ //g"`
45
if [ -z "$df" -o "$df" = "0x00000000" -o $((df + 1 - 1)) -eq 0 ]
46
then
47
NETDATA_CONFIG_DEBUG=0
@@ -50,8 +50,8 @@ then
50
fi
51
52
# find the user to run as
53
- NETDATA_CONFIG_USER="`grep 'run as user = ' netdata.conf | head -n 1 | cut -d '=' -f 2 | sed s"/ //g"`"
54
- NETDATA_CONFIG_WEB_DIR="`grep 'web files directory = ' netdata.conf | head -n 1 | cut -d '=' -f 2 | sed -e s"/^ \+//g" -e s"/ \+$//g"`"
53
+ NETDATA_CONFIG_USER="`grep 'run as user = ' conf.d/netdata.conf | head -n 1 | cut -d '=' -f 2 | sed s"/ //g"`"
54
+ NETDATA_CONFIG_WEB_DIR="`grep 'web files directory = ' conf.d/netdata.conf | head -n 1 | cut -d '=' -f 2 | sed -e s"/^ \+//g" -e s"/ \+$//g"`"
55
fi
56
fi
57
@@ -60,7 +60,7 @@ if [ $NETDATA_CONFIG_DEBUG -eq 1 ]
60
then
61
ulimit -c unlimited
62
gcc -Wall -Wextra -ggdb -o netdata netdata.c -lpthread -lz || exit 1
63
- debug_opts="-df 0xfffffadf -dl netdata.log"
63
+ debug_opts="-df 0xfffffadf"
64
else
65
gcc -Wall -O3 -o netdata netdata.c -lpthread -lz || exit 1
66
debug_opts="-df 0x00000000"
@@ -84,25 +84,25 @@ then
84
fi
85
86
echo "Starting netdata..."
87
-if [ -f netdata.conf ]
87
+if [ -f conf.d/netdata.conf ]
88
then
89
`pwd`/netdata
90
else
91
- touch netdata.conf
91
+ touch conf.d/netdata.conf
92
93
if [ "$USER" = "root" ]
94
then
95
- `pwd`/netdata $debug_opts -d -u $NETDATA_CONFIG_USER -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
95
+ `pwd`/netdata $debug_opts -u $NETDATA_CONFIG_USER -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
96
else
97
- `pwd`/netdata $debug_opts -d -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
97
+ `pwd`/netdata $debug_opts -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
98
fi
99
100
sleep 2
101
- wget 2>/dev/null -O netdata.conf.new http://localhost:$NETDATA_CONFIG_PORT/netdata.conf
102
- mv netdata.conf.new netdata.conf
101
+ wget 2>/dev/null -O conf.d/netdata.conf.new http://localhost:$NETDATA_CONFIG_PORT/netdata.conf
102
+ mv conf.d/netdata.conf.new conf.d/netdata.conf
103
104
echo "Hit http://127.0.0.1:$NETDATA_CONFIG_PORT/ from your browser."
105
- echo "You can edit config options in file netdata.conf"
105
+ echo "You can edit config options in file conf.d/netdata.conf"
106
fi
107
108
echo