@cryptotaxi247 / netdata-1 / commits / ef5c84b69

apps.plugin: added calls counter and isolatored file counter only to new files processed; #1827

Costa Tsaousis (ktsaou) committed Feb 26, 2017 at 12:24 UTC ef5c84b6933bf5758b8f48ae4891060e2cd5235f
1 file changed +27 -15
src/apps_plugin.c
+27 -15
@@ -64,6 +64,7 @@ static int
64
65 static size_t
66 global_iterations_counter = 1,
67 + calls_counter = 0,
68 file_counter = 0;
69
70
@@ -831,7 +832,7 @@ static inline int read_proc_pid_stat(struct pid_stat *p) {
832
833 p->last_stat_collected_usec = p->stat_collected_usec;
834 p->stat_collected_usec = now_monotonic_usec();
834 - file_counter++;
835 + calls_counter++;
836
837 // p->pid = str2pid_t(procfile_lineword(ff, 0, 0));
838 char *comm = procfile_lineword(ff, 0, 1);
@@ -983,7 +984,7 @@ static inline int read_proc_pid_statm(struct pid_stat *p) {
984 ff = procfile_readall(ff);
985 if(unlikely(!ff)) goto cleanup;
986
986 - file_counter++;
987 + calls_counter++;
988
989 p->statm_size = str2kernel_uint_t(procfile_lineword(ff, 0, 0));
990 p->statm_resident = str2kernel_uint_t(procfile_lineword(ff, 0, 1));
@@ -1022,7 +1023,7 @@ static inline int read_proc_pid_io(struct pid_stat *p) {
1023 ff = procfile_readall(ff);
1024 if(unlikely(!ff)) goto cleanup;
1025
1025 - file_counter++;
1026 + calls_counter++;
1027
1028 p->last_io_collected_usec = p->io_collected_usec;
1029 p->io_collected_usec = now_monotonic_usec();
@@ -1098,7 +1099,7 @@ static inline int read_proc_stat() {
1099 last_collected_usec = collected_usec;
1100 collected_usec = now_monotonic_usec();
1101
1101 - file_counter++;
1102 + calls_counter++;
1103
1104 kernel_uint_t last;
1105
@@ -1387,8 +1388,9 @@ static inline void make_all_pid_fds_negative(struct pid_stat *p) {
1388 }
1389
1390 static inline void cleanup_negative_pid_fds(struct pid_stat *p) {
1390 - int *fd = p->fds, *end = &p->fds[p->fds_size];
1391 - while(fd < end) {
1391 + int *fd = p->fds, *fdend = &p->fds[p->fds_size];
1392 +
1393 + while(fd < fdend) {
1394 if(unlikely(*fd < 0)) {
1395 file_descriptor_not_used(-(*fd));
1396 *fd++ = 0;
@@ -1429,7 +1431,7 @@ static inline int read_pid_file_descriptors(struct pid_stat *p) {
1431 continue;
1432
1433 // get its number
1432 - int fdid = (int)str2l(de->d_name);
1434 + int fdid = (int) str2l(de->d_name);
1435 if(unlikely(fdid < 0)) continue;
1436
1437 // check if the fds array is small
@@ -1437,7 +1439,12 @@ static inline int read_pid_file_descriptors(struct pid_stat *p) {
1439 // it is small, extend it
1440
1441 if(unlikely(debug))
1440 - fprintf(stderr, "apps.plugin: extending fd memory slots for %s from %d to %d\n", p->comm, p->fds_size, fdid + MAX_SPARE_FDS);
1442 + fprintf(stderr
1443 + , "apps.plugin: extending fd memory slots for %s from %d to %d\n"
1444 + , p->comm
1445 + , p->fds_size
1446 + , fdid + MAX_SPARE_FDS
1447 + );
1448
1449 p->fds = reallocz(p->fds, (fdid + MAX_SPARE_FDS) * sizeof(int));
1450
@@ -1468,9 +1475,10 @@ static inline int read_pid_file_descriptors(struct pid_stat *p) {
1475 p->fds[fdid] = file_descriptor_find_or_add(linkname);
1476 }
1477
1471 - // else make it positive again, we need it
1472 - // of course, the actual file may have changed, but we don't care so much
1473 - // FIXME: we could compare the inode as returned by readdir dirent structure
1478 + // else make it positive again, we need it
1479 + // of course, the actual file may have changed, but we don't care so much
1480 + // FIXME: we could compare the inode as returned by readdir dirent structure
1481 + // UPDATE: no we cannot use inodes - under /proc inodes don't change when the link is changed
1482
1483 else
1484 p->fds[fdid] = -p->fds[fdid];
@@ -1952,10 +1960,11 @@ static void cleanup_exited_pids(void) {
1960 if(unlikely(debug && (p->keep || p->keeploops)))
1961 fprintf(stderr, " > CLEANUP cannot keep exited process %d (%s) anymore - removing it.\n", p->pid, p->comm);
1962
1955 - for(c = 0 ; c < p->fds_size ; c++) if(p->fds[c] > 0) {
1956 - file_descriptor_not_used(p->fds[c]);
1957 - p->fds[c] = 0;
1958 - }
1963 + for(c = 0; c < p->fds_size; c++)
1964 + if(p->fds[c] > 0) {
1965 + file_descriptor_not_used(p->fds[c]);
1966 + p->fds[c] = 0;
1967 + }
1968
1969 pid_t r = p->pid;
1970 p = p->next;
@@ -2398,6 +2407,7 @@ static usec_t send_resource_usage_to_netdata() {
2407 "DIMENSION user '' incremental 1 1000\n"
2408 "DIMENSION system '' incremental 1 1000\n"
2409 "CHART netdata.apps_files '' 'Apps Plugin Files' 'files/s' apps.plugin netdata.apps_files line 140001 %1$d\n"
2410 + "DIMENSION calls '' incremental 1 1\n"
2411 "DIMENSION files '' incremental 1 1\n"
2412 "DIMENSION pids '' absolute 1 1\n"
2413 "DIMENSION fds '' absolute 1 1\n"
@@ -2431,6 +2441,7 @@ static usec_t send_resource_usage_to_netdata() {
2441 "SET system = %llu\n"
2442 "END\n"
2443 "BEGIN netdata.apps_files %llu\n"
2444 + "SET calls = %zu\n"
2445 "SET files = %zu\n"
2446 "SET pids = %zu\n"
2447 "SET fds = %d\n"
@@ -2447,6 +2458,7 @@ static usec_t send_resource_usage_to_netdata() {
2458 , cpuuser
2459 , cpusyst
2460 , usec
2461 + , calls_counter
2462 , file_counter
2463 , all_pids_count
2464 , all_files_len