X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fapps_plugin.c;h=b1bf06bee9dc2aee1a3d100b5c86a1e0571e9a4e;hb=909e26f825bc1f6f907231761412c885331fec7e;hp=89aea6ce7af077b36eeda4dba28c64dec99fad27;hpb=ebf1ad56d0030fd4ae041a73c833ea26a6c3b747;p=netdata.git diff --git a/src/apps_plugin.c b/src/apps_plugin.c index 89aea6ce..b1bf06be 100644 --- a/src/apps_plugin.c +++ b/src/apps_plugin.c @@ -90,7 +90,8 @@ static int static size_t global_iterations_counter = 1, calls_counter = 0, - file_counter = 0; + file_counter = 0, + targets_assignment_counter = 0; // ---------------------------------------------------------------------------- @@ -749,6 +750,8 @@ static inline int managed_log(struct pid_stat *p, uint32_t log, int status) { } static inline void assign_target_to_pid(struct pid_stat *p) { + targets_assignment_counter++; + uint32_t hash = simple_hash(p->comm); size_t pclen = strlen(p->comm); @@ -1077,6 +1080,7 @@ static inline int read_proc_pid_statm(struct pid_stat *p, void *ptr) { return 1; +#ifndef __FreeBSD__ cleanup: p->statm_size = 0; p->statm_resident = 0; @@ -1086,6 +1090,7 @@ cleanup: // p->statm_data = 0; // p->statm_dirty = 0; return 0; +#endif } static inline int read_proc_pid_io(struct pid_stat *p, void *ptr) { @@ -1139,6 +1144,7 @@ static inline int read_proc_pid_io(struct pid_stat *p, void *ptr) { return 1; +#ifndef __FreeBSD__ cleanup: p->io_logical_bytes_read = 0; p->io_logical_bytes_written = 0; @@ -1148,23 +1154,24 @@ cleanup: p->io_storage_bytes_written = 0; // p->io_cancelled_write_bytes = 0; return 0; +#endif } static inline int read_proc_stat() { #ifdef __FreeBSD__ long cp_time[CPUSTATES]; - int i; + static kernel_uint_t utime_raw = 0, stime_raw = 0, ntime_raw = 0; if (unlikely(CPUSTATES != 5)) { error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES); goto cleanup; } - if (unlikely(GETSYSCTL("kern.cp_time", cp_time))) goto cleanup; + if (unlikely(GETSYSCTL_BY_NAME("kern.cp_time", cp_time))) goto cleanup; #else static char filename[FILENAME_MAX + 1] = ""; static procfile *ff = NULL; -#endif static kernel_uint_t utime_raw = 0, stime_raw = 0, gtime_raw = 0, gntime_raw = 0, ntime_raw = 0; +#endif static usec_t collected_usec = 0, last_collected_usec = 0; #ifndef __FreeBSD__ @@ -1997,6 +2004,7 @@ static inline void link_all_processes_to_their_parents(void) { // to avoid filling up all disk space // if debug is enabled, all errors are printed +#ifndef __FreeBSD__ static int compar_pid(const void *pid1, const void *pid2) { struct pid_stat *p1 = all_pids[*((pid_t *)pid1)]; @@ -2007,6 +2015,7 @@ static int compar_pid(const void *pid1, const void *pid2) { else return 1; } +#endif static inline int collect_data_for_pid(pid_t pid, void *ptr) { if(unlikely(pid < INIT_PID || pid > pid_max)) { @@ -2093,7 +2102,9 @@ static int collect_data_for_all_processes(void) { #endif if(all_pids_count) { +#ifndef __FreeBSD__ size_t slc = 0; +#endif for(p = root_of_pids; p ; p = p->next) { p->read = 0; // mark it as not read, so that collect_data_for_pid() will read it p->updated = 0; @@ -2651,12 +2662,13 @@ static usec_t send_resource_usage_to_netdata() { , "CHART netdata.apps_cpu '' 'Apps Plugin CPU' 'milliseconds/s' apps.plugin netdata.apps_cpu stacked 140000 %1$d\n" "DIMENSION user '' incremental 1 1000\n" "DIMENSION system '' incremental 1 1000\n" - "CHART netdata.apps_files '' 'Apps Plugin Files' 'files/s' apps.plugin netdata.apps_files line 140001 %1$d\n" + "CHART netdata.apps_sizes '' 'Apps Plugin Files' 'files/s' apps.plugin netdata.apps_sizes line 140001 %1$d\n" "DIMENSION calls '' incremental 1 1\n" "DIMENSION files '' incremental 1 1\n" "DIMENSION pids '' absolute 1 1\n" "DIMENSION fds '' absolute 1 1\n" "DIMENSION targets '' absolute 1 1\n" + "DIMENSION new_pids 'new pids' incremental 1 1\n" "CHART netdata.apps_fix '' 'Apps Plugin Normalization Ratios' 'percentage' apps.plugin netdata.apps_fix line 140002 %1$d\n" "DIMENSION utime '' absolute 1 %2$llu\n" "DIMENSION stime '' absolute 1 %2$llu\n" @@ -2685,12 +2697,13 @@ static usec_t send_resource_usage_to_netdata() { "SET user = %llu\n" "SET system = %llu\n" "END\n" - "BEGIN netdata.apps_files %llu\n" + "BEGIN netdata.apps_sizes %llu\n" "SET calls = %zu\n" "SET files = %zu\n" "SET pids = %zu\n" "SET fds = %d\n" "SET targets = %zu\n" + "SET new_pids = %zu\n" "END\n" "BEGIN netdata.apps_fix %llu\n" "SET utime = %u\n" @@ -2708,6 +2721,7 @@ static usec_t send_resource_usage_to_netdata() { , all_pids_count , all_files_len , apps_groups_targets_count + , targets_assignment_counter , usec , (unsigned int)(utime_fix_ratio * 100 * RATES_DETAIL) , (unsigned int)(stime_fix_ratio * 100 * RATES_DETAIL) @@ -3097,20 +3111,6 @@ static void send_charts_updates_to_netdata(struct target *root, const char *type fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, RATES_DETAIL); } -#ifndef __FreeBSD__ - fprintf(stdout, "CHART %s.lreads '' '%s Disk Logical Reads' 'kilobytes/s' disk %s.lreads stacked 20042 %d\n", type, title, type, update_every); - for (w = root; w ; w = w->next) { - if(unlikely(w->exposed)) - fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL); - } - - fprintf(stdout, "CHART %s.lwrites '' '%s I/O Logical Writes' 'kilobytes/s' disk %s.lwrites stacked 20042 %d\n", type, title, type, update_every); - for (w = root; w ; w = w->next) { - if(unlikely(w->exposed)) - fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL); - } -#endif - #ifdef __FreeBSD__ fprintf(stdout, "CHART %s.preads '' '%s Disk Reads' 'blocks/s' disk %s.preads stacked 20002 %d\n", type, title, type, update_every); for (w = root; w ; w = w->next) { @@ -3135,6 +3135,18 @@ static void send_charts_updates_to_netdata(struct target *root, const char *type if(unlikely(w->exposed)) fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL); } + + fprintf(stdout, "CHART %s.lreads '' '%s Disk Logical Reads' 'kilobytes/s' disk %s.lreads stacked 20042 %d\n", type, title, type, update_every); + for (w = root; w ; w = w->next) { + if(unlikely(w->exposed)) + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL); + } + + fprintf(stdout, "CHART %s.lwrites '' '%s I/O Logical Writes' 'kilobytes/s' disk %s.lwrites stacked 20042 %d\n", type, title, type, update_every); + for (w = root; w ; w = w->next) { + if(unlikely(w->exposed)) + fprintf(stdout, "DIMENSION %s '' absolute 1 %llu\n", w->name, 1024LLU * RATES_DETAIL); + } #endif if(enable_file_charts) { @@ -3195,7 +3207,7 @@ static void parse_args(int argc, char **argv) } } - if(strcmp("version", argv[i]) == 0 || strcmp("-v", argv[i]) == 0) { + if(strcmp("version", argv[i]) == 0 || strcmp("-v", argv[i]) == 0 || strcmp("-V", argv[i]) == 0) { printf("apps.plugin %s\n", VERSION); exit(0); } @@ -3265,7 +3277,7 @@ static void parse_args(int argc, char **argv) "\n" " This program is a data collector plugin for netdata.\n" "\n" - " Valid command line options:\n" + " Available command line options:\n" "\n" " SECONDS set the data collection frequency\n" "\n" @@ -3288,7 +3300,7 @@ static void parse_args(int argc, char **argv) " apps_groups.conf\n" " (default NAME=groups)\n" "\n" - " version print program version and exit\n" + " version or -v or -V print program version and exit\n" "\n" , VERSION );