@cryptotaxi247 / netdata-1 / commits / 0b8260ae2

added apps.processes, count of processes per app

Costa Tsaousis (ktsaou) committed May 5, 2014 at 20:04 UTC 0b8260ae2beb08f4155e49a1530697880683b941
1 file changed +22 -7
apps_plugin.c
+22 -7
@@ -47,7 +47,7 @@ struct wanted {
47 unsigned long long num_threads;
48 unsigned long long rss;
49
50 - int merge_count;
50 + unsigned long merge_count; // how many processes have been merged to this
51
52 struct wanted *target; // the one that will be reported to netdata
53 struct wanted *next;
@@ -161,7 +161,7 @@ struct pid_stat {
161 int updated;
162 int merged;
163 int new_entry;
164 - int merge_count;
164 + unsigned long merge_count;
165 struct wanted *target;
166 struct pid_stat *parent;
167 struct pid_stat *prev;
@@ -235,7 +235,7 @@ int update_from_proc(void)
235
236 int fd = open(filename, O_RDONLY);
237 if(fd == -1) {
238 - if(errno != ENOENT) fprintf(stderr, "Cannot open file '%s' for reading (%s).\n", filename, strerror(errno));
238 + if(errno != ENOENT && errno != ESRCH) fprintf(stderr, "Cannot open file '%s' for reading (%s).\n", filename, strerror(errno));
239 continue;
240 }
241
@@ -357,7 +357,7 @@ void merge_processes(void)
357 found = 0;
358 for(p = root; p ; p = p->next) {
359 if(!p->childs && !p->merged && p->parent && p->parent->childs) {
360 - if(debug) fprintf(stderr, "\tMerging %d %s to %d %s (count: %d)\n", p->pid, p->comm, p->ppid, all_pids[p->ppid]->comm, p->parent->merge_count+1);
360 + if(debug) fprintf(stderr, "\tMerging %d %s to %d %s (count: %lu)\n", p->pid, p->comm, p->ppid, all_pids[p->ppid]->comm, p->parent->merge_count+1);
361
362 p->parent->minflt += p->minflt;
363 p->parent->majflt += p->majflt;
@@ -375,7 +375,7 @@ void merge_processes(void)
375 p->parent->childs--;
376 p->merged = 1;
377
378 - p->parent->merge_count++;
378 + p->parent->merge_count += p->merge_count + 1;
379
380 // the parent inherits the child's target, if it does not have a target itself
381 if(p->target && !p->parent->target) {
@@ -428,8 +428,8 @@ void merge_processes(void)
428 p->target->num_threads += p->num_threads;
429 p->target->rss += p->rss;
430
431 - p->target->merge_count++;
432 - if(debug) fprintf(stderr, "\tAgregating %s pid %d on %s (count: %d)\n", p->comm, p->pid, p->target->name, p->target->merge_count);
431 + p->target->merge_count += p->merge_count + 1;
432 + if(debug) fprintf(stderr, "\tAgregating %s pid %d on %s (count: %lu)\n", p->comm, p->pid, p->target->name, p->target->merge_count);
433 }
434 }
435 }
@@ -471,6 +471,14 @@ void show_dimensions(void)
471 }
472 fprintf(stdout, "END\n");
473
474 + fprintf(stdout, "BEGIN apps.processes\n");
475 + for (w = wanted_root; w ; w = w->next) {
476 + if(w->target) continue;
477 +
478 + fprintf(stdout, "SET %s = %lu\n", w->name, w->merge_count);
479 + }
480 + fprintf(stdout, "END\n");
481 +
482 fprintf(stdout, "BEGIN apps.rss\n");
483 for (w = wanted_root; w ; w = w->next) {
484 if(w->target) continue;
@@ -523,6 +531,13 @@ void show_charts(void)
531 fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
532 }
533
534 + fprintf(stdout, "CHART apps.processes '' 'Applications Processes' 'processes' apps apps stacked 20004 %d\n", update_every);
535 + for (w = wanted_root; w ; w = w->next) {
536 + if(w->target) continue;
537 +
538 + fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
539 + }
540 +
541 fprintf(stdout, "CHART apps.cpu_user '' 'Applications CPU User Time' 'cpu time %%' apps none stacked 20020 %d\n", update_every);
542 for (w = wanted_root; w ; w = w->next) {
543 if(w->target) continue;