From: Patrik Weiskircher Date: Thu, 1 Oct 2009 11:57:11 +0000 (+0200) Subject: Added fork rate collecting to processes plugin. X-Git-Tag: collectd-4.9.0~66 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=0d8ba9a85008de5280f9c64bbdcbf5f9ac9b922d Added fork rate collecting to processes plugin. Signed-off-by: Florian Forster --- diff --git a/src/processes.c b/src/processes.c index 4f515184..3623f73f 100644 --- a/src/processes.c +++ b/src/processes.c @@ -839,6 +839,65 @@ static char *ps_get_cmdline (pid_t pid, char *name, char *buf, size_t buf_len) } return buf; } /* char *ps_get_cmdline (...) */ + +static unsigned long read_fork_rate () +{ + FILE *proc_stat; + char buf[1024]; + unsigned long result = 0; + int numfields; + char *fields[2]; + + proc_stat = fopen("/proc/stat", "r"); + if (proc_stat == NULL) { + char errbuf[1024]; + ERROR ("processes plugin: fopen (/proc/stat) failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return 0; + } + + while (fgets (buf, sizeof(buf), proc_stat) != NULL) + { + if (strncmp (buf, "processes", 9)) + continue; + numfields = strsplit(buf, fields, 2); + if (numfields != 2) { + ERROR ("processes plugin: processes in /proc/stat contain more than 2 fields."); + break; + } + + result = strtoul(fields[1], NULL, 10); + if (errno == ERANGE && result == ULONG_MAX) { + ERROR ("processes plugin: processes value in /proc/stat overflows."); + break; + } + + break; + } + + fclose(proc_stat); + + return result; +} + +static void ps_submit_fork_rate (unsigned long value) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].derive = value; + + vl.values = values; + vl.values_len = 1; + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "processes", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "fork_rate", sizeof (vl.type)); + sstrncpy (vl.type_instance, "", sizeof (vl.type_instance)); + + plugin_dispatch_values (&vl); +} + #endif /* KERNEL_LINUX */ #if HAVE_THREAD_INFO @@ -1161,6 +1220,8 @@ static int ps_read (void) procstat_entry_t pse; char state; + unsigned long fork_rate; + procstat_t *ps_ptr; running = sleeping = zombies = stopped = paging = blocked = 0; @@ -1234,6 +1295,9 @@ static int ps_read (void) for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next) ps_submit_proc_list (ps_ptr); + + fork_rate = read_fork_rate(); + ps_submit_fork_rate(fork_rate); /* #endif KERNEL_LINUX */ #elif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD diff --git a/src/types.db b/src/types.db index 10e15974..399dbd23 100644 --- a/src/types.db +++ b/src/types.db @@ -60,6 +60,7 @@ files value:GAUGE:0:U frequency frequency:GAUGE:0:U frequency_offset ppm:GAUGE:-1000000:1000000 fscache_stat value:COUNTER:0:4294967295 +fork_rate value:DERIVE:0:U gauge value:GAUGE:U:U http_request_methods count:COUNTER:0:134217728 http_requests count:COUNTER:0:134217728