X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fprocesses.c;h=ff4012660dff3888c5cb28cfa75107da3c7ed8cf;hb=1fdb04e6cb573ad06b914b9371f21ffb255b1d13;hp=c22f0f6f8265e160f61971624a58955744c24638;hpb=b8be503b2b50366a9c498ba7e4ab66a228c6dfbf;p=collectd.git diff --git a/src/processes.c b/src/processes.c index c22f0f6f..ff401266 100644 --- a/src/processes.c +++ b/src/processes.c @@ -25,7 +25,6 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #include "configfile.h" /* Include header files for the mach system, if they exist.. */ @@ -93,63 +92,6 @@ #define BUFSIZE 256 -static data_source_t state_dsrc[1] = -{ - {"value", DS_TYPE_GAUGE, 0.0, 65535.0} -}; - -static data_set_t state_ds = -{ - "ps_state", 1, state_dsrc -}; - -static data_source_t rss_dsrc[1] = -{ - /* max = 2^63 - 1 */ - {"value", DS_TYPE_GAUGE, 0.0, 9223372036854775807.0} -}; - -static data_set_t rss_ds = -{ - "ps_rss", 1, rss_dsrc -}; - -static data_source_t time_dsrc[2] = -{ - /* 1 second in user-mode per second ought to be enough.. */ - {"user", DS_TYPE_COUNTER, 0.0, 1000000.0}, - {"syst", DS_TYPE_COUNTER, 0.0, 1000000.0} -}; - -static data_set_t time_ds = -{ - "ps_cputime", 2, time_dsrc -}; - -static data_source_t count_dsrc[2] = -{ - /* 1 second in user-mode per second ought to be enough.. */ - {"processes", DS_TYPE_GAUGE, 0.0, 1000000.0}, - {"threads", DS_TYPE_GAUGE, 0.0, 1000000.0} -}; - -static data_set_t count_ds = -{ - "ps_count", 2, count_dsrc -}; - -static data_source_t pagefaults_dsrc[2] = -{ - /* max = 2^63 - 1 */ - {"minflt", DS_TYPE_COUNTER, 0.0, 9223372036854775807.0}, - {"majflt", DS_TYPE_COUNTER, 0.0, 9223372036854775807.0} -}; - -static data_set_t pagefaults_ds = -{ - "ps_pagefaults", 2, pagefaults_dsrc -}; - #if PROCESSES_HAVE_READ #if HAVE_THREAD_INFO | KERNEL_LINUX static const char *config_keys[] = @@ -388,7 +330,7 @@ static void ps_list_reset (void) { if (pse->age > 10) { - DBG ("Removing this procstat entry cause it's too old: " + DEBUG ("Removing this procstat entry cause it's too old: " "id = %lu; name = %s;", pse->id, ps->name); @@ -451,7 +393,7 @@ static int ps_init (void) &pset_list, &pset_list_len)) != KERN_SUCCESS) { - syslog (LOG_ERR, "host_processor_sets failed: %s\n", + ERROR ("host_processor_sets failed: %s\n", mach_error_string (status)); pset_list = NULL; pset_list_len = 0; @@ -461,7 +403,7 @@ static int ps_init (void) #elif KERNEL_LINUX pagesize_g = sysconf(_SC_PAGESIZE); - DBG ("pagesize_g = %li; CONFIG_HZ = %i;", + DEBUG ("pagesize_g = %li; CONFIG_HZ = %i;", pagesize_g, CONFIG_HZ); #endif /* KERNEL_LINUX */ @@ -478,7 +420,7 @@ static void ps_submit_state (const char *state, double value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname); + strcpy (vl.host, hostname_g); strcpy (vl.plugin, "processes"); strcpy (vl.plugin_instance, ""); strncpy (vl.type_instance, state, sizeof (vl.type_instance)); @@ -494,7 +436,7 @@ static void ps_submit_proc_list (procstat_t *ps) vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname); + strcpy (vl.host, hostname_g); strcpy (vl.plugin, "processes"); strncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance)); @@ -517,7 +459,7 @@ static void ps_submit_proc_list (procstat_t *ps) vl.values_len = 2; plugin_dispatch_values ("ps_pagefaults", &vl); - DBG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; " + DEBUG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; " "vmem_minflt_counter = %lu; vmem_majflt_counter = %lu; " "cpu_user_counter = %lu; cpu_system_counter = %lu;", ps->name, ps->num_proc, ps->num_lwp, ps->vmem_rss, @@ -541,7 +483,7 @@ static int *ps_read_tasks (int pid) if ((dh = opendir (dirname)) == NULL) { - DBG ("Failed to open directory `%s'", dirname); + DEBUG ("Failed to open directory `%s'", dirname); return (NULL); } @@ -561,7 +503,7 @@ static int *ps_read_tasks (int pid) { if (list != NULL) free (list); - syslog (LOG_ERR, "processes plugin: " + ERROR ("processes plugin: " "Failed to allocate more memory."); return (NULL); } @@ -623,20 +565,17 @@ int ps_read_process (int pid, procstat_t *ps, char *state) fields_len = strsplit (buffer, fields, 64); if (fields_len < 24) { - DBG ("`%s' has only %i fields..", - filename, fields_len); + DEBUG ("processes plugin: ps_read_process (pid = %i):" + " `%s' has only %i fields..", + (int) pid, filename, fields_len); return (-1); } - else if (fields_len != 41) - { - DBG ("WARNING: (fields_len = %i) != 41", fields_len); - } /* copy the name, strip brackets in the process */ name_len = strlen (fields[1]) - 2; if ((fields[1][0] != '(') || (fields[1][name_len + 1] != ')')) { - DBG ("No brackets found in process name: `%s'", fields[1]); + DEBUG ("No brackets found in process name: `%s'", fields[1]); return (-1); } fields[1] = fields[1] + 1; @@ -645,17 +584,21 @@ int ps_read_process (int pid, procstat_t *ps, char *state) ppid = atoi (fields[3]); - if ((tasks = ps_read_tasks (pid)) == NULL) + *state = fields[2][0]; + + if (*state == 'Z') { - /* This happends for zombied, e.g. */ - DBG ("ps_read_tasks (%i) failed.", pid); - *state = 'Z'; ps->num_lwp = 0; ps->num_proc = 0; } + else if ((tasks = ps_read_tasks (pid)) == NULL) + { + /* Kernel 2.4 or so */ + ps->num_lwp = 1; + ps->num_proc = 1; + } else { - *state = '\0'; ps->num_lwp = 0; ps->num_proc = 1; for (i = 0; tasks[i] != 0; i++) @@ -665,10 +608,10 @@ int ps_read_process (int pid, procstat_t *ps, char *state) tasks = NULL; } - /* Leave the rest at zero if this is only an LWP */ + /* Leave the rest at zero if this is only a zombi */ if (ps->num_proc == 0) { - DBG ("This is only an LWP: pid = %i; name = %s;", + DEBUG ("This is only a zombi: pid = %i; name = %s;", pid, ps->name); return (0); } @@ -688,8 +631,6 @@ int ps_read_process (int pid, procstat_t *ps, char *state) ps->cpu_system_counter = (unsigned long) cpu_system_counter; ps->vmem_rss = (unsigned long) vmem_rss; - *state = fields[2][0]; - /* success */ return (0); } /* int ps_read_process (...) */ @@ -721,7 +662,7 @@ static int mach_get_task_name (task_t t, int *pid, char *name, size_t name_max_l strncpy (name, kp.kp_proc.p_comm, name_max_len - 1); name[name_max_len - 1] = '\0'; - DBG ("pid = %i; name = %s;", *pid, name); + DEBUG ("pid = %i; name = %s;", *pid, name); /* We don't do the special handling for `p_comm == "LaunchCFMApp"' as * `top' does it, because it is a lot of work and only used when @@ -777,7 +718,7 @@ static int ps_read (void) pset_list[pset], &port_pset_priv)) != KERN_SUCCESS) { - syslog (LOG_ERR, "host_processor_set_priv failed: %s\n", + ERROR ("host_processor_set_priv failed: %s\n", mach_error_string (status)); continue; } @@ -786,7 +727,7 @@ static int ps_read (void) &task_list, &task_list_len)) != KERN_SUCCESS) { - syslog (LOG_ERR, "processor_set_tasks failed: %s\n", + ERROR ("processor_set_tasks failed: %s\n", mach_error_string (status)); mach_port_deallocate (port_task_self, port_pset_priv); continue; @@ -820,7 +761,7 @@ static int ps_read (void) &task_basic_info_len); if (status != KERN_SUCCESS) { - syslog (LOG_ERR, "task_info failed: %s", + ERROR ("task_info failed: %s", mach_error_string (status)); continue; /* with next thread_list */ } @@ -832,7 +773,7 @@ static int ps_read (void) &task_events_info_len); if (status != KERN_SUCCESS) { - syslog (LOG_ERR, "task_info failed: %s", + ERROR ("task_info failed: %s", mach_error_string (status)); continue; /* with next thread_list */ } @@ -844,7 +785,7 @@ static int ps_read (void) &task_absolutetime_info_len); if (status != KERN_SUCCESS) { - syslog (LOG_ERR, "task_info failed: %s", + ERROR ("task_info failed: %s", mach_error_string (status)); continue; /* with next thread_list */ } @@ -868,7 +809,7 @@ static int ps_read (void) * thread is nonsense, since the task/process * is dead. */ zombies++; - DBG ("task_threads failed: %s", + DEBUG ("task_threads failed: %s", mach_error_string (status)); if (task_list[task] != port_task_self) mach_port_deallocate (port_task_self, @@ -885,7 +826,7 @@ static int ps_read (void) &thread_data_len); if (status != KERN_SUCCESS) { - syslog (LOG_ERR, "thread_info failed: %s", + ERROR ("thread_info failed: %s", mach_error_string (status)); if (task_list[task] != port_task_self) mach_port_deallocate (port_task_self, @@ -917,8 +858,7 @@ static int ps_read (void) * There's only zombie tasks, which are * handled above. */ default: - syslog (LOG_WARNING, - "Unknown thread status: %s", + WARNING ("Unknown thread status: %s", thread_data.run_state); break; } /* switch (thread_data.run_state) */ @@ -928,7 +868,7 @@ static int ps_read (void) status = mach_port_deallocate (port_task_self, thread_list[thread]); if (status != KERN_SUCCESS) - syslog (LOG_ERR, "mach_port_deallocate failed: %s", + ERROR ("mach_port_deallocate failed: %s", mach_error_string (status)); } } /* for (thread_list) */ @@ -938,7 +878,7 @@ static int ps_read (void) thread_list_len * sizeof (thread_act_t))) != KERN_SUCCESS) { - syslog (LOG_ERR, "vm_deallocate failed: %s", + ERROR ("vm_deallocate failed: %s", mach_error_string (status)); } thread_list = NULL; @@ -952,7 +892,7 @@ static int ps_read (void) status = mach_port_deallocate (port_task_self, task_list[task]); if (status != KERN_SUCCESS) - syslog (LOG_ERR, "mach_port_deallocate failed: %s", + ERROR ("mach_port_deallocate failed: %s", mach_error_string (status)); } @@ -964,7 +904,7 @@ static int ps_read (void) (vm_address_t) task_list, task_list_len * sizeof (task_t))) != KERN_SUCCESS) { - syslog (LOG_ERR, "vm_deallocate failed: %s", + ERROR ("vm_deallocate failed: %s", mach_error_string (status)); } task_list = NULL; @@ -973,7 +913,7 @@ static int ps_read (void) if ((status = mach_port_deallocate (port_task_self, port_pset_priv)) != KERN_SUCCESS) { - syslog (LOG_ERR, "mach_port_deallocate failed: %s", + ERROR ("mach_port_deallocate failed: %s", mach_error_string (status)); } } /* for (pset_list) */ @@ -1012,7 +952,9 @@ static int ps_read (void) if ((proc = opendir ("/proc")) == NULL) { - syslog (LOG_ERR, "Cannot open `/proc': %s", strerror (errno)); + char errbuf[1024]; + ERROR ("Cannot open `/proc': %s", + sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } @@ -1027,7 +969,7 @@ static int ps_read (void) status = ps_read_process (pid, &ps, &state); if (status != 0) { - DBG ("ps_read_process failed: %i", status); + DEBUG ("ps_read_process failed: %i", status); continue; } @@ -1080,12 +1022,6 @@ static int ps_read (void) void module_register (void) { - plugin_register_data_set (&state_ds); - plugin_register_data_set (&rss_ds); - plugin_register_data_set (&time_ds); - plugin_register_data_set (&count_ds ); - plugin_register_data_set (&pagefaults_ds ); - #if PROCESSES_HAVE_READ #if HAVE_THREAD_INFO | KERNEL_LINUX plugin_register_config ("processes", ps_config, @@ -1094,5 +1030,4 @@ void module_register (void) plugin_register_init ("processes", ps_init); plugin_register_read ("processes", ps_read); #endif /* PROCESSES_HAVE_READ */ -} - +} /* void module_register */