@cryptotaxi247 / netdata-1 / commits / 36ea52301

hide not so important charts; allow per chart debugging in apps.plugin

Costa Tsaousis (ktsaou) committed May 22, 2014 at 00:47 UTC 36ea523016ce15cb495481cdb8520c81efb17222
3 files changed +52 -19
apps_plugin.c
+48 -18
@@ -81,6 +81,8 @@ struct target {
81
82 unsigned long processes; // how many processes have been merged to this
83 int exposed; // if set, we have sent this to netdata
84 + int hidden; // if set, we set the hidden flag on the dimension
85 + int debug;
86
87 struct target *target; // the one that will be reported to netdata
88 struct target *next;
@@ -91,9 +93,12 @@ unsigned long long file_counter = 0;
93
94 struct target *get_target(const char *id, struct target *target)
95 {
96 + const char *nid = id;
97 + if(nid[0] == '-') nid++;
98 +
99 struct target *w;
100 for(w = target_root ; w ; w = w->next)
96 - if(strncmp(id, w->id, MAX_NAME) == 0) return w;
101 + if(strncmp(nid, w->id, MAX_NAME) == 0) return w;
102
103 w = calloc(sizeof(struct target), 1);
104 if(!w) {
@@ -101,9 +106,11 @@ struct target *get_target(const char *id, struct target *target)
106 return NULL;
107 }
108
104 - strncpy(w->id, id, MAX_NAME);
105 - strncpy(w->name, id, MAX_NAME);
106 - strncpy(w->compare, id, MAX_COMPARE_NAME);
109 + strncpy(w->id, nid, MAX_NAME);
110 + strncpy(w->name, nid, MAX_NAME);
111 + strncpy(w->compare, nid, MAX_COMPARE_NAME);
112 + if(id[0] == '-') w->hidden = 1;
113 +
114 w->target = target;
115
116 w->next = target_root;
@@ -147,6 +154,7 @@ int read_process_groups(const char *name)
154
155 long line = 0;
156 while(fgets(buffer, 4096, fp) != NULL) {
157 + int whidden = 0, wdebug = 0;
158 line++;
159
160 // if(debug) fprintf(stderr, "\tread %s\n", buffer);
@@ -162,6 +170,26 @@ int read_process_groups(const char *name)
170 if(t) t = trim(t);
171 if(!t || !*t) continue;
172
173 + while(t[0]) {
174 + int stop = 1;
175 +
176 + switch(t[0]) {
177 + case '-':
178 + stop = 0;
179 + whidden = 1;
180 + t++;
181 + break;
182 +
183 + case '+':
184 + stop = 0;
185 + wdebug = 1;
186 + t++;
187 + break;
188 + }
189 +
190 + if(stop) break;
191 + }
192 +
193 if(debug) fprintf(stderr, "\t\ttarget %s\n", t);
194
195 struct target *w = NULL;
@@ -173,6 +201,8 @@ int read_process_groups(const char *name)
201 if(!p || !*p) continue;
202
203 struct target *n = get_target(p, w);
204 + n->hidden = whidden;
205 + n->debug = wdebug;
206 if(!w) w = n;
207
208 count++;
@@ -454,7 +484,7 @@ int update_from_proc(void)
484 strncpy(p->comm, name, MAX_COMPARE_NAME);
485 p->comm[MAX_COMPARE_NAME] = '\0';
486
457 - if(debug) fprintf(stderr, "VALUES: %s utime=%llu, stime=%llu, cutime=%llu, cstime=%llu, minflt=%llu, majflt=%llu, cminflt=%llu, cmajflt=%llu\n", p->comm, p->utime, p->stime, p->cutime, p->cstime, p->minflt, p->majflt, p->cminflt, p->cmajflt);
487 + if(debug || (p->target && p->target->debug)) fprintf(stderr, "VALUES: %s utime=%llu, stime=%llu, cutime=%llu, cstime=%llu, minflt=%llu, majflt=%llu, cminflt=%llu, cmajflt=%llu\n", p->comm, p->utime, p->stime, p->cutime, p->cstime, p->minflt, p->majflt, p->cminflt, p->cmajflt);
488
489 if(parsed < 39) fprintf(stderr, "file %s gave %d results (expected 44)\n", filename, parsed);
490
@@ -465,13 +495,13 @@ int update_from_proc(void)
495
496 struct target *w;
497 for(w = target_root; w ; w = w->next) {
468 - // if(debug) fprintf(stderr, "\t\tcomparing '%s' with '%s'\n", w->compare, p->comm);
498 + // if(debug || (p->target && p->target->debug)) fprintf(stderr, "\t\tcomparing '%s' with '%s'\n", w->compare, p->comm);
499
500 if(strcmp(w->compare, p->comm) == 0) {
501 if(w->target) p->target = w->target;
502 else p->target = w;
503
474 - if(debug) fprintf(stderr, "\t\t%s linked to target %s\n", p->comm, p->target->name);
504 + if(debug || (p->target && p->target->debug)) fprintf(stderr, "\t\t%s linked to target %s\n", p->comm, p->target->name);
505 }
506 }
507 }
@@ -501,7 +531,7 @@ int update_from_proc(void)
531 }
532 else if(bytes > 10) {
533 buffer[bytes] = '\0';
504 - if(debug) fprintf(stderr, "READ statm: %s", buffer);
534 + if(debug || (p->target && p->target->debug)) fprintf(stderr, "READ statm: %s", buffer);
535
536 parsed = sscanf(buffer,
537 "%llu %llu %llu %llu %llu %llu %llu"
@@ -539,7 +569,7 @@ int update_from_proc(void)
569 }
570 else if(bytes > 10) {
571 buffer[bytes] = '\0';
542 - if(debug) fprintf(stderr, "READ io: %s", buffer);
572 + if(debug || (p->target && p->target->debug)) fprintf(stderr, "READ io: %s", buffer);
573
574 parsed = sscanf(buffer,
575 "rchar: %llu\nwchar: %llu\nsyscr: %llu\nsyscw: %llu\nread_bytes: %llu\nwrite_bytes: %llu\ncancelled_write_bytes: %llu"
@@ -616,7 +646,7 @@ void update_statistics(void)
646 // link all parents and update childs count
647 for(p = root; p ; p = p->next) {
648 if(p->ppid > 0 && p->ppid <= pid_max && all_pids[p->ppid]) {
619 - if(debug) fprintf(stderr, "\tParent of %d %s is %d %s\n", p->pid, p->comm, p->ppid, all_pids[p->ppid]->comm);
649 + if(debug || (p->target && p->target->debug)) fprintf(stderr, "\tParent of %d %s is %d %s\n", p->pid, p->comm, p->ppid, all_pids[p->ppid]->comm);
650
651 p->parent = all_pids[p->ppid];
652 p->parent->childs++;
@@ -643,7 +673,7 @@ void update_statistics(void)
673 // the parent inherits the child's target, if it does not have a target itself
674 if(p->target && !p->parent->target) {
675 p->parent->target = p->target;
646 - if(debug) fprintf(stderr, "\t\ttarget %s is inherited by %d %s from its child %d %s.\n", p->target->name, p->parent->pid, p->parent->comm, p->pid, p->comm);
676 + if(debug || (p->target && p->target->debug)) fprintf(stderr, "\t\ttarget %s is inherited by %d %s from its child %d %s.\n", p->target->name, p->parent->pid, p->parent->comm, p->pid, p->comm);
677 }
678
679 found++;
@@ -807,7 +837,7 @@ void update_statistics(void)
837
838 p->target->processes++;
839
810 - if(debug) fprintf(stderr, "\tAgregating %s pid %d on %s utime=%llu, stime=%llu, cutime=%llu, cstime=%llu, minflt=%llu, majflt=%llu, cminflt=%llu, cmajflt=%llu\n", p->comm, p->pid, p->target->name, p->utime, p->stime, p->cutime, p->cstime, p->minflt, p->majflt, p->cminflt, p->cmajflt);
840 + if(debug || p->target->debug) fprintf(stderr, "\tAgregating %s pid %d on %s utime=%llu, stime=%llu, cutime=%llu, cstime=%llu, minflt=%llu, majflt=%llu, cminflt=%llu, cmajflt=%llu\n", p->comm, p->pid, p->target->name, p->utime, p->stime, p->cutime, p->cstime, p->minflt, p->majflt, p->cminflt, p->cmajflt);
841
842 /* if(p->utime - p->old_utime > 100) fprintf(stderr, "BIG CHANGE: %d %s utime increased by %llu from %llu to %llu\n", p->pid, p->comm, p->utime - p->old_utime, p->old_utime, p->utime);
843 if(p->cutime - p->old_cutime > 100) fprintf(stderr, "BIG CHANGE: %d %s cutime increased by %llu from %llu to %llu\n", p->pid, p->comm, p->cutime - p->old_cutime, p->old_cutime, p->cutime);
@@ -1025,7 +1055,7 @@ void show_charts(void)
1055 if(!w->exposed && w->processes) {
1056 newly_added++;
1057 w->exposed = 1;
1028 - if(debug) fprintf(stderr, "%s just added - regenerating charts.\n", w->name);
1058 + if(debug || w->debug) fprintf(stderr, "%s just added - regenerating charts.\n", w->name);
1059 }
1060
1061 // nothing more to show
@@ -1037,7 +1067,7 @@ void show_charts(void)
1067 for (w = target_root; w ; w = w->next) {
1068 if(w->target || (!w->processes && !w->exposed)) continue;
1069
1040 - fprintf(stdout, "DIMENSION %s '' incremental 100 %llu\n", w->name, Hertz);
1070 + fprintf(stdout, "DIMENSION %s '' incremental 100 %llu %s\n", w->name, Hertz, w->hidden?"hidden":"");
1071 }
1072
1073 fprintf(stdout, "CHART apps.mem '' 'Apps Dedicated Memory (w/o shared)' 'MB' apps apps stacked 20003 %d\n", update_every);
@@ -1082,21 +1112,21 @@ void show_charts(void)
1112 fprintf(stdout, "DIMENSION %s '' incremental 1 1\n", w->name);
1113 }
1114
1085 - fprintf(stdout, "CHART apps.minor_faults '' 'Apps Minor Page Faults' 'page faults/s' apps apps stacked 20011 %d\n", update_every);
1115 + fprintf(stdout, "CHART apps.minor_faults '' 'Apps Minor Page Faults' 'page faults/s' apps none stacked 20011 %d\n", update_every);
1116 for (w = target_root; w ; w = w->next) {
1117 if(w->target || (!w->processes && !w->exposed)) continue;
1118
1119 fprintf(stdout, "DIMENSION %s '' incremental 1 1\n", w->name);
1120 }
1121
1092 - fprintf(stdout, "CHART apps.lreads '' 'Apps Disk Logical Reads' 'kilobytes/s' apps apps stacked 20042 %d\n", update_every);
1122 + fprintf(stdout, "CHART apps.lreads '' 'Apps Disk Logical Reads' 'kilobytes/s' apps none stacked 20042 %d\n", update_every);
1123 for (w = target_root; w ; w = w->next) {
1124 if(w->target || (!w->processes && !w->exposed)) continue;
1125
1126 fprintf(stdout, "DIMENSION %s '' incremental 1 1024\n", w->name);
1127 }
1128
1099 - fprintf(stdout, "CHART apps.lwrites '' 'Apps I/O Logical Writes' 'kilobytes/s' apps apps stacked 20042 %d\n", update_every);
1129 + fprintf(stdout, "CHART apps.lwrites '' 'Apps I/O Logical Writes' 'kilobytes/s' apps none stacked 20042 %d\n", update_every);
1130 for (w = target_root; w ; w = w->next) {
1131 if(w->target || (!w->processes && !w->exposed)) continue;
1132
@@ -1121,7 +1151,7 @@ void show_charts(void)
1151 fprintf(stdout, "DIMENSION user '' incremental 1 1000\n");
1152 fprintf(stdout, "DIMENSION system '' incremental 1 1000\n");
1153
1124 - fprintf(stdout, "CHART netdata.apps_files '' 'Apps Plugin Files' 'files/s' netdata netdata line 10001 %d\n", update_every);
1154 + fprintf(stdout, "CHART netdata.apps_files '' 'Apps Plugin Files' 'files/s' netdata none line 10001 %d\n", update_every);
1155 fprintf(stdout, "DIMENSION files '' incremental-no-interpolation 1 1\n");
1156
1157 fflush(stdout);
conf.d/apps_groups.conf
+2
@@ -17,6 +17,8 @@
17 #
18 # The process names are the same to the ones returned by: ps -e
19 #
20 +# If a group_name starts with a -, the dimension will be hidden (cpu chart only)
21 +#
22
23 media: mplayer vlc xine mediatomb
24 squid: squid squid2 squid3
netdata.c
+2 -1
@@ -94,6 +94,7 @@
94 #define D_PLUGINSD 0x00000800
95 #define D_CHILDS 0x00001000
96 #define D_EXIT 0x00002000
97 +#define D_CHECKS 0x00004000
98
99 #define CT_APPLICATION_JSON 1
100 #define CT_TEXT_PLAIN 2
@@ -7421,7 +7422,7 @@ int main(int argc, char **argv)
7422 else if(pthread_detach(*p_pluginsd))
7423 error("Cannot request detach of newly created plugins.d thread.");
7424
7424 - if(config_get_boolean("plugins", "checks", 1)) {
7425 + if(config_get_boolean("plugins", "checks", (debug_flags & D_CHECKS)?1:0)) {
7426 p_checks = malloc(sizeof(pthread_t));
7427 if(pthread_create(p_checks, NULL, checks_main, NULL))
7428 error("failed to create new thread for checks.");