Added fork rate collecting to processes plugin.
authorPatrik Weiskircher <weiskircher@inqnet.at>
Thu, 1 Oct 2009 11:57:11 +0000 (13:57 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Fri, 2 Oct 2009 06:52:25 +0000 (08:52 +0200)
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/processes.c
src/types.db

index 4f51518..3623f73 100644 (file)
@@ -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
index 10e1597..399dbd2 100644 (file)
@@ -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