@cryptotaxi247 / netdata-1 / commits / e777150db

charts for applications open files, sockets, pipes, inotifications, events, timers and signal fds

Costa Tsaousis (ktsaou) committed May 22, 2014 at 22:59 UTC e777150db46fb2ba3d7964add26fac48408fe56d
1 file changed +199
apps_plugin.c
+199
@@ -79,6 +79,17 @@ struct target {
79 unsigned long long fix_io_storage_bytes_written;
80 unsigned long long fix_io_cancelled_write_bytes;
81
82 + unsigned long long openfiles;
83 + unsigned long long openpipes;
84 + unsigned long long opensockets;
85 + unsigned long long openinotifies;
86 + unsigned long long openeventfds;
87 + unsigned long long opentimerfds;
88 + unsigned long long opensignalfds;
89 + unsigned long long openeventpolls;
90 + unsigned long long openanoninodes;
91 + unsigned long long openother;
92 +
93 unsigned long processes; // how many processes have been merged to this
94 int exposed; // if set, we have sent this to netdata
95 int hidden; // if set, we set the hidden flag on the dimension
@@ -340,6 +351,17 @@ struct pid_stat {
351 unsigned long long diff_cmajflt;
352 */
353
354 + unsigned long long openfiles;
355 + unsigned long long openpipes;
356 + unsigned long long opensockets;
357 + unsigned long long openinotifies;
358 + unsigned long long openeventfds;
359 + unsigned long long opentimerfds;
360 + unsigned long long opensignalfds;
361 + unsigned long long openeventpolls;
362 + unsigned long long openanoninodes;
363 + unsigned long long openother;
364 +
365 int childs; // number of processes directly referencing this
366 int updated;
367 int merged;
@@ -410,6 +432,17 @@ int update_from_proc(void)
432 p->childs = 0;
433 p->merged = 0;
434 p->new_entry = 0;
435 +
436 + p->openfiles = 0;
437 + p->openpipes = 0;
438 + p->opensockets = 0;
439 + p->openinotifies = 0;
440 + p->openeventfds = 0;
441 + p->openeventpolls = 0;
442 + p->opentimerfds = 0;
443 + p->opensignalfds = 0;
444 + p->openanoninodes = 0;
445 + p->openother = 0;
446 }
447
448 while((file = readdir(dir))) {
@@ -586,6 +619,45 @@ int update_from_proc(void)
619 }
620 }
621
622 + // --------------------------------------------------------------------
623 + // /proc/<pid>/fd
624 +
625 + snprintf(filename, FILENAME_MAX, "/proc/%s/fd", file->d_name);
626 + DIR *fds = opendir(filename);
627 + if(fds) {
628 + struct dirent *de;
629 + char fdname[FILENAME_MAX + 1];
630 + char linkname[FILENAME_MAX + 1];
631 +
632 + while((de = readdir(fds))) {
633 + if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
634 +
635 + sprintf(fdname, "/proc/%s/fd/%s", file->d_name, de->d_name);
636 + int l = readlink(fdname, linkname, FILENAME_MAX);
637 + if(l == -1) {
638 + fprintf(stderr, "Cannot read link %s\n", fdname);
639 + continue;
640 + }
641 + file_counter++;
642 +
643 + linkname[l] = '\0';
644 +
645 + if(linkname[0] == '/') p->openfiles++;
646 + else if(strncmp(linkname, "pipe:", 5) == 0) p->openpipes++;
647 + else if(strncmp(linkname, "socket:", 7) == 0) p->opensockets++;
648 + else if(strcmp(linkname, "anon_inode:inotify") == 0) p->openinotifies++;
649 + else if(strcmp(linkname, "anon_inode:[eventfd]") == 0) p->openeventfds++;
650 + else if(strcmp(linkname, "anon_inode:[eventpoll]") == 0) p->openeventpolls++;
651 + else if(strcmp(linkname, "anon_inode:[timerfd]") == 0) p->opentimerfds++;
652 + else if(strcmp(linkname, "anon_inode:[signalfd]") == 0) p->opensignalfds++;
653 + else if(strncmp(linkname, "anon_inode:", 11) == 0) {
654 + fprintf(stderr, "anonymous inode: %s\n", linkname);
655 + p->openanoninodes++;
656 + }
657 + else p->openother++;
658 + }
659 + closedir(fds);
660 + }
661
662 // --------------------------------------------------------------------
663 // done!
@@ -794,6 +866,17 @@ void update_statistics(void)
866 w->io_storage_bytes_read = 0;
867 w->io_storage_bytes_written = 0;
868 w->io_cancelled_write_bytes = 0;
869 +
870 + w->openfiles = 0;
871 + w->openpipes = 0;
872 + w->opensockets = 0;
873 + w->openinotifies = 0;
874 + w->openeventfds = 0;
875 + w->opentimerfds = 0;
876 + w->opensignalfds = 0;
877 + w->openeventpolls = 0;
878 + w->openanoninodes = 0;
879 + w->openother = 0;
880 }
881
882 /* walk_down(0, 1);
@@ -835,6 +918,17 @@ void update_statistics(void)
918 p->target->io_storage_bytes_written += p->io_storage_bytes_written;
919 p->target->io_cancelled_write_bytes += p->io_cancelled_write_bytes;
920
921 + p->target->openfiles += p->openfiles;
922 + p->target->openpipes += p->openpipes;
923 + p->target->opensockets += p->opensockets;
924 + p->target->openinotifies += p->openinotifies;
925 + p->target->openeventfds += p->openeventfds;
926 + p->target->opentimerfds += p->opentimerfds;
927 + p->target->opensignalfds += p->opensignalfds;
928 + p->target->openeventpolls += p->openeventpolls;
929 + p->target->openanoninodes += p->openanoninodes;
930 + p->target->openother += p->openother;
931 +
932 p->target->processes++;
933
934 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);
@@ -1035,6 +1129,62 @@ void show_dimensions(void)
1129 }
1130 fprintf(stdout, "END\n");
1131
1132 + fprintf(stdout, "BEGIN apps.files %llu\n", usec);
1133 + for (w = target_root; w ; w = w->next) {
1134 + if(w->target || (!w->processes && !w->exposed)) continue;
1135 +
1136 + fprintf(stdout, "SET %s = %llu\n", w->name, w->openfiles);
1137 + }
1138 + fprintf(stdout, "END\n");
1139 +
1140 + fprintf(stdout, "BEGIN apps.sockets %llu\n", usec);
1141 + for (w = target_root; w ; w = w->next) {
1142 + if(w->target || (!w->processes && !w->exposed)) continue;
1143 +
1144 + fprintf(stdout, "SET %s = %llu\n", w->name, w->opensockets);
1145 + }
1146 + fprintf(stdout, "END\n");
1147 +
1148 + fprintf(stdout, "BEGIN apps.pipes %llu\n", usec);
1149 + for (w = target_root; w ; w = w->next) {
1150 + if(w->target || (!w->processes && !w->exposed)) continue;
1151 +
1152 + fprintf(stdout, "SET %s = %llu\n", w->name, w->openpipes);
1153 + }
1154 + fprintf(stdout, "END\n");
1155 +
1156 + fprintf(stdout, "BEGIN apps.inotify %llu\n", usec);
1157 + for (w = target_root; w ; w = w->next) {
1158 + if(w->target || (!w->processes && !w->exposed)) continue;
1159 +
1160 + fprintf(stdout, "SET %s = %llu\n", w->name, w->openinotifies);
1161 + }
1162 + fprintf(stdout, "END\n");
1163 +
1164 + fprintf(stdout, "BEGIN apps.eventfd %llu\n", usec);
1165 + for (w = target_root; w ; w = w->next) {
1166 + if(w->target || (!w->processes && !w->exposed)) continue;
1167 +
1168 + fprintf(stdout, "SET %s = %llu\n", w->name, w->openeventfds + w->openeventpolls);
1169 + }
1170 + fprintf(stdout, "END\n");
1171 +
1172 + fprintf(stdout, "BEGIN apps.timerfd %llu\n", usec);
1173 + for (w = target_root; w ; w = w->next) {
1174 + if(w->target || (!w->processes && !w->exposed)) continue;
1175 +
1176 + fprintf(stdout, "SET %s = %llu\n", w->name, w->opentimerfds);
1177 + }
1178 + fprintf(stdout, "END\n");
1179 +
1180 + fprintf(stdout, "BEGIN apps.signalfd %llu\n", usec);
1181 + for (w = target_root; w ; w = w->next) {
1182 + if(w->target || (!w->processes && !w->exposed)) continue;
1183 +
1184 + fprintf(stdout, "SET %s = %llu\n", w->name, w->opensignalfds);
1185 + }
1186 + fprintf(stdout, "END\n");
1187 +
1188 fprintf(stdout, "BEGIN netdata.apps_cpu %llu\n", usec);
1189 fprintf(stdout, "SET user = %llu\n", cpuuser);
1190 fprintf(stdout, "SET system = %llu\n", cpusyst);
@@ -1147,6 +1297,55 @@ void show_charts(void)
1297 fprintf(stdout, "DIMENSION %s '' incremental 1 1024\n", w->name);
1298 }
1299
1300 + fprintf(stdout, "CHART apps.files '' 'Apps Open Files' 'open files' apps apps stacked 20050 %d\n", update_every);
1301 + for (w = target_root; w ; w = w->next) {
1302 + if(w->target || (!w->processes && !w->exposed)) continue;
1303 +
1304 + fprintf(stdout, "DIMENSION %s '' absolute-no-interpolation 1 1\n", w->name);
1305 + }
1306 +
1307 + fprintf(stdout, "CHART apps.sockets '' 'Apps Open Sockets' 'open sockets' apps apps stacked 20051 %d\n", update_every);
1308 + for (w = target_root; w ; w = w->next) {
1309 + if(w->target || (!w->processes && !w->exposed)) continue;
1310 +
1311 + fprintf(stdout, "DIMENSION %s '' absolute-no-interpolation 1 1\n", w->name);
1312 + }
1313 +
1314 + fprintf(stdout, "CHART apps.pipes '' 'Apps Pipes' 'open pipes' apps none stacked 20053 %d\n", update_every);
1315 + for (w = target_root; w ; w = w->next) {
1316 + if(w->target || (!w->processes && !w->exposed)) continue;
1317 +
1318 + fprintf(stdout, "DIMENSION %s '' absolute-no-interpolation 1 1\n", w->name);
1319 + }
1320 +
1321 + fprintf(stdout, "CHART apps.inotify '' 'Apps inotifies' 'open inotifies' apps none stacked 20054 %d\n", update_every);
1322 + for (w = target_root; w ; w = w->next) {
1323 + if(w->target || (!w->processes && !w->exposed)) continue;
1324 +
1325 + fprintf(stdout, "DIMENSION %s '' absolute-no-interpolation 1 1\n", w->name);
1326 + }
1327 +
1328 + fprintf(stdout, "CHART apps.eventfd '' 'Apps Event File Descriptors' 'open event fds' apps none stacked 20055 %d\n", update_every);
1329 + for (w = target_root; w ; w = w->next) {
1330 + if(w->target || (!w->processes && !w->exposed)) continue;
1331 +
1332 + fprintf(stdout, "DIMENSION %s '' absolute-no-interpolation 1 1\n", w->name);
1333 + }
1334 +
1335 + fprintf(stdout, "CHART apps.timerfd '' 'Apps Timer File Descriptors' 'open timer fds' apps none stacked 20057 %d\n", update_every);
1336 + for (w = target_root; w ; w = w->next) {
1337 + if(w->target || (!w->processes && !w->exposed)) continue;
1338 +
1339 + fprintf(stdout, "DIMENSION %s '' absolute-no-interpolation 1 1\n", w->name);
1340 + }
1341 +
1342 + fprintf(stdout, "CHART apps.signalfd '' 'Apps Timer File Descriptors' 'open timer fds' apps none stacked 20058 %d\n", update_every);
1343 + for (w = target_root; w ; w = w->next) {
1344 + if(w->target || (!w->processes && !w->exposed)) continue;
1345 +
1346 + fprintf(stdout, "DIMENSION %s '' absolute-no-interpolation 1 1\n", w->name);
1347 + }
1348 +
1349 fprintf(stdout, "CHART netdata.apps_cpu '' 'Apps Plugin CPU' 'milliseconds/s' netdata netdata stacked 10000 %d\n", update_every);
1350 fprintf(stdout, "DIMENSION user '' incremental 1 1000\n");
1351 fprintf(stdout, "DIMENSION system '' incremental 1 1000\n");