diff options
Diffstat (limited to 'src/collectors/apps.plugin')
-rw-r--r-- | src/collectors/apps.plugin/apps_groups.conf | 7 | ||||
-rw-r--r-- | src/collectors/apps.plugin/apps_output.c | 57 | ||||
-rw-r--r-- | src/collectors/apps.plugin/apps_plugin.c | 39 | ||||
-rw-r--r-- | src/collectors/apps.plugin/apps_plugin.h | 10 | ||||
-rw-r--r-- | src/collectors/apps.plugin/apps_proc_pid_limits.c | 2 | ||||
-rw-r--r-- | src/collectors/apps.plugin/apps_proc_pids.c | 40 |
6 files changed, 55 insertions, 100 deletions
diff --git a/src/collectors/apps.plugin/apps_groups.conf b/src/collectors/apps.plugin/apps_groups.conf index 41b69ed6..724616c1 100644 --- a/src/collectors/apps.plugin/apps_groups.conf +++ b/src/collectors/apps.plugin/apps_groups.conf @@ -92,7 +92,6 @@ go.d.plugin: *go.d.plugin* slabinfo.plugin: *slabinfo.plugin* ebpf.plugin: *ebpf.plugin* debugfs.plugin: *debugfs.plugin* -logs-management.plugin: *logs-management.plugin* # agent-service-discovery agent_sd: agent_sd @@ -376,6 +375,12 @@ inetd: inetd xinetd # ----------------------------------------------------------------------------- # other application servers +i2pd: i2pd + +rethinkdb: rethinkdb + +beanstalkd: beanstalkd + rspamd: rspamd consul: consul diff --git a/src/collectors/apps.plugin/apps_output.c b/src/collectors/apps.plugin/apps_output.c index 0bf8e9ae..84928e64 100644 --- a/src/collectors/apps.plugin/apps_output.c +++ b/src/collectors/apps.plugin/apps_output.c @@ -62,30 +62,6 @@ void send_resource_usage_to_netdata(usec_t dt) { "DIMENSION new_pids 'new pids' incremental 1 1\n" , update_every ); - - fprintf(stdout, - "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" - "DIMENSION gtime '' absolute 1 %2$llu\n" - "DIMENSION minflt '' absolute 1 %2$llu\n" - "DIMENSION majflt '' absolute 1 %2$llu\n" - , update_every - , RATES_DETAIL - ); - - if(include_exited_childs) - fprintf(stdout, - "CHART netdata.apps_children_fix '' 'Apps Plugin Exited Children Normalization Ratios' 'percentage' apps.plugin netdata.apps_children_fix line 140003 %1$d\n" - "DIMENSION cutime '' absolute 1 %2$llu\n" - "DIMENSION cstime '' absolute 1 %2$llu\n" - "DIMENSION cgtime '' absolute 1 %2$llu\n" - "DIMENSION cminflt '' absolute 1 %2$llu\n" - "DIMENSION cmajflt '' absolute 1 %2$llu\n" - , update_every - , RATES_DETAIL - ); - } fprintf(stdout, @@ -118,39 +94,6 @@ void send_resource_usage_to_netdata(usec_t dt) { , apps_groups_targets_count , targets_assignment_counter ); - - fprintf(stdout, - "BEGIN netdata.apps_fix %"PRIu64"\n" - "SET utime = %u\n" - "SET stime = %u\n" - "SET gtime = %u\n" - "SET minflt = %u\n" - "SET majflt = %u\n" - "END\n" - , dt - , (unsigned int)(utime_fix_ratio * 100 * RATES_DETAIL) - , (unsigned int)(stime_fix_ratio * 100 * RATES_DETAIL) - , (unsigned int)(gtime_fix_ratio * 100 * RATES_DETAIL) - , (unsigned int)(minflt_fix_ratio * 100 * RATES_DETAIL) - , (unsigned int)(majflt_fix_ratio * 100 * RATES_DETAIL) - ); - - if(include_exited_childs) - fprintf(stdout, - "BEGIN netdata.apps_children_fix %"PRIu64"\n" - "SET cutime = %u\n" - "SET cstime = %u\n" - "SET cgtime = %u\n" - "SET cminflt = %u\n" - "SET cmajflt = %u\n" - "END\n" - , dt - , (unsigned int)(cutime_fix_ratio * 100 * RATES_DETAIL) - , (unsigned int)(cstime_fix_ratio * 100 * RATES_DETAIL) - , (unsigned int)(cgtime_fix_ratio * 100 * RATES_DETAIL) - , (unsigned int)(cminflt_fix_ratio * 100 * RATES_DETAIL) - , (unsigned int)(cmajflt_fix_ratio * 100 * RATES_DETAIL) - ); } void send_collected_data_to_netdata(struct target *root, const char *type, usec_t dt) { diff --git a/src/collectors/apps.plugin/apps_plugin.c b/src/collectors/apps.plugin/apps_plugin.c index b660f817..8fe1ff00 100644 --- a/src/collectors/apps.plugin/apps_plugin.c +++ b/src/collectors/apps.plugin/apps_plugin.c @@ -51,7 +51,6 @@ size_t inodes_changed_counter = 0, links_changed_counter = 0, targets_assignment_counter = 0, - all_pids_count = 0, // the number of processes running apps_groups_targets_count = 0; // # of apps_groups.conf targets int @@ -136,20 +135,6 @@ struct target size_t pagesize; -struct pid_stat - *root_of_pids = NULL, // global list of all processes running - **all_pids = NULL; // to avoid allocations, we pre-allocate - // a pointer for each pid in the entire pid space. - -#if (ALL_PIDS_ARE_READ_INSTANTLY == 0) -// Another pre-allocated list of all possible pids. -// We need it to pids and assign them a unique sortlist id, so that we -// read parents before children. This is needed to prevent a situation where -// a child is found running, but until we read its parent, it has exited and -// its parent has accumulated its resources. -pid_t *all_pids_sortlist = NULL; -#endif - // ---------------------------------------------------------------------------- int managed_log(struct pid_stat *p, PID_LOG log, int status) { @@ -208,7 +193,7 @@ int managed_log(struct pid_stat *p, PID_LOG log, int status) { } } } - errno = 0; + errno_clear(); } else if(unlikely(p->log_thrown & log)) { // netdata_log_error("unsetting log %u on pid %d", log, p->pid); @@ -300,12 +285,14 @@ static void apply_apps_groups_targets_inheritance(void) { } // init goes always to default target - if(all_pids[INIT_PID] && !all_pids[INIT_PID]->matched_by_config) - all_pids[INIT_PID]->target = apps_groups_default_target; + struct pid_stat *pi = find_pid_entry(INIT_PID); + if(pi && !pi->matched_by_config) + pi->target = apps_groups_default_target; // pid 0 goes always to default target - if(all_pids[0] && !all_pids[INIT_PID]->matched_by_config) - all_pids[0]->target = apps_groups_default_target; + pi = find_pid_entry(0); + if(pi && !pi->matched_by_config) + pi->target = apps_groups_default_target; // give a default target on all top level processes if(unlikely(debug_enabled)) loops++; @@ -320,8 +307,9 @@ static void apply_apps_groups_targets_inheritance(void) { p->sortlist = sortlist++; } - if(all_pids[1]) - all_pids[1]->sortlist = sortlist++; + pi = find_pid_entry(1); + if(pi) + pi->sortlist = sortlist++; // give a target to all merged child processes found = 1; @@ -1052,12 +1040,7 @@ int main(int argc, char **argv) { netdata_log_info("started on pid %d", getpid()); users_and_groups_init(); - -#if (ALL_PIDS_ARE_READ_INSTANTLY == 0) - all_pids_sortlist = callocz(sizeof(pid_t), (size_t)pid_max + 1); -#endif - - all_pids = callocz(sizeof(struct pid_stat *), (size_t) pid_max + 1); + pids_init(); // ------------------------------------------------------------------------ // the event loop for functions diff --git a/src/collectors/apps.plugin/apps_plugin.h b/src/collectors/apps.plugin/apps_plugin.h index ce4d815a..a085872d 100644 --- a/src/collectors/apps.plugin/apps_plugin.h +++ b/src/collectors/apps.plugin/apps_plugin.h @@ -17,9 +17,7 @@ #include <sys/proc_info.h> #include <sys/sysctl.h> #include <mach/mach_time.h> // For mach_timebase_info_data_t and mach_timebase_info -#endif -#if defined(__APPLE__) extern mach_timebase_info_data_t mach_info; #endif @@ -47,7 +45,6 @@ struct pid_info { struct proc_taskinfo taskinfo; struct proc_bsdinfo bsdinfo; struct rusage_info_v4 rusageinfo; - }; #endif @@ -467,9 +464,7 @@ extern struct target *users_root_target, *groups_root_target; -extern struct pid_stat - *root_of_pids, - **all_pids; +extern struct pid_stat *root_of_pids; extern int update_every; extern unsigned int time_factor; @@ -559,4 +554,7 @@ void send_charts_updates_to_netdata(struct target *root, const char *type, const void send_collected_data_to_netdata(struct target *root, const char *type, usec_t dt); void send_resource_usage_to_netdata(usec_t dt); +void pids_init(void); +struct pid_stat *find_pid_entry(pid_t pid); + #endif //NETDATA_APPS_PLUGIN_H diff --git a/src/collectors/apps.plugin/apps_proc_pid_limits.c b/src/collectors/apps.plugin/apps_proc_pid_limits.c index a1e15f63..7485086b 100644 --- a/src/collectors/apps.plugin/apps_proc_pid_limits.c +++ b/src/collectors/apps.plugin/apps_proc_pid_limits.c @@ -33,7 +33,7 @@ static inline bool read_proc_pid_limits_per_os(struct pid_stat *p, void *ptr __m bool ret = false; bool read_limits = false; - errno = 0; + errno_clear(); proc_pid_limits_buffer[0] = '\0'; kernel_uint_t all_fds = pid_openfds_sum(p); diff --git a/src/collectors/apps.plugin/apps_proc_pids.c b/src/collectors/apps.plugin/apps_proc_pids.c index fd7e776f..b53060d6 100644 --- a/src/collectors/apps.plugin/apps_proc_pids.c +++ b/src/collectors/apps.plugin/apps_proc_pids.c @@ -2,18 +2,44 @@ #include "apps_plugin.h" -static inline struct pid_stat *get_pid_entry(pid_t pid) { - if(likely(all_pids[pid])) - return all_pids[pid]; +static struct pid_stat **all_pids = NULL; +size_t all_pids_count = 0; // the number of processes running + +struct pid_stat *root_of_pids = NULL; // global linked list of all processes running + +#if (ALL_PIDS_ARE_READ_INSTANTLY == 0) +// Another pre-allocated list of all possible pids. +// We need it to assign them a unique sortlist id, so that we +// read parents before children. This is needed to prevent a situation where +// a child is found running, but until we read its parent, it has exited and +// its parent has accumulated its resources. +pid_t *all_pids_sortlist = NULL; +#endif + +void pids_init(void) { +#if (ALL_PIDS_ARE_READ_INSTANTLY == 0) + all_pids_sortlist = callocz(sizeof(pid_t), (size_t)pid_max + 1); +#endif + + all_pids = callocz(sizeof(struct pid_stat *), (size_t) pid_max + 1); +} - struct pid_stat *p = callocz(sizeof(struct pid_stat), 1); +inline struct pid_stat *find_pid_entry(pid_t pid) { + return all_pids[pid]; +} + +static inline struct pid_stat *get_or_allocate_pid_entry(pid_t pid) { + struct pid_stat *p = find_pid_entry(pid); + if(likely(p)) + return p; + + p = callocz(sizeof(struct pid_stat), 1); p->fds = mallocz(sizeof(struct pid_fd) * MAX_SPARE_FDS); p->fds_size = MAX_SPARE_FDS; init_pid_fds(p, 0, p->fds_size); p->pid = pid; DOUBLE_LINKED_LIST_APPEND_ITEM_UNSAFE(root_of_pids, p, prev, next); - all_pids[pid] = p; all_pids_count++; @@ -21,7 +47,7 @@ static inline struct pid_stat *get_pid_entry(pid_t pid) { } static inline void del_pid_entry(pid_t pid) { - struct pid_stat *p = all_pids[pid]; + struct pid_stat *p = find_pid_entry(pid); if(unlikely(!p)) { netdata_log_error("attempted to free pid %d that is not allocated.", pid); @@ -62,7 +88,7 @@ static inline int collect_data_for_pid(pid_t pid, void *ptr) { return 0; } - struct pid_stat *p = get_pid_entry(pid); + struct pid_stat *p = get_or_allocate_pid_entry(pid); if(unlikely(!p || p->read)) return 0; p->read = true; |