]> arthur.barton.de Git - netdata.git/commitdiff
added /proc/interrupts #12
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Tue, 29 Sep 2015 19:59:30 +0000 (22:59 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Tue, 29 Sep 2015 19:59:30 +0000 (22:59 +0300)
src/Makefile
src/plugin_proc.c
src/plugin_proc.h
src/proc_interrupts.c [new file with mode: 0755]

index 3e098f88bddba87591edb9604b34081d3b3ad24e..739812bf34b7c54b6dfb24edc3eeb6ec9765e255 100755 (executable)
@@ -24,7 +24,7 @@ endif
 
 COMMON_FLAGS = BIN_DIR='$(BIN_DIR)' CONFIG_DIR='$(CONFIG_DIR)' LOG_DIR='$(LOG_DIR)' PLUGINS_DIR='$(PLUGINS_DIR)'
 
-proc_sources = proc_net_dev.c proc_net_ip_vs_stats.c proc_diskstats.c proc_meminfo.c proc_net_netstat.c proc_net_snmp.c proc_net_stat_conntrack.c proc_stat.c proc_vmstat.c proc_net_rpc_nfsd.c proc_sys_kernel_random_entropy_avail.c
+proc_sources = proc_net_dev.c proc_net_ip_vs_stats.c proc_diskstats.c proc_meminfo.c proc_net_netstat.c proc_net_snmp.c proc_net_stat_conntrack.c proc_stat.c proc_vmstat.c proc_net_rpc_nfsd.c proc_sys_kernel_random_entropy_avail.c proc_interrupts.c
 sources = avl.c dictionary.c procfile.c common.c log.c popen.c url.c config.c web_buffer.c storage_number.c web_client.c global_statistics.c rrd.c rrd2json.c web_server.c plugins_d.c daemon.c plugin_tc.c plugin_checks.c plugin_idlejitter.c plugin_proc.c unit_test.c main.c
 libs    = -pthread -lz
 
index e14c181cd1fb05f1ccab74966ccfcc53ef96dde5..f1169a26515af0b84e5f865dbcab9a823ca9b21f 100755 (executable)
@@ -43,6 +43,7 @@ void *proc_main(void *ptr)
        int vdo_proc_vmstat                     = !config_get_boolean("plugin:proc", "/proc/vmstat", 1);
        int vdo_proc_net_rpc_nfsd               = !config_get_boolean("plugin:proc", "/proc/net/rpc/nfsd", 1);
        int vdo_proc_sys_kernel_random_entropy_avail    = !config_get_boolean("plugin:proc", "/proc/sys/kernel/random/entropy_avail", 1);
+       int vdo_proc_interrupts                 = !config_get_boolean("plugin:proc", "/proc/interrupts", 1);
        int vdo_cpu_netdata                     = !config_get_boolean("plugin:proc", "netdata server resources", 1);
 
        RRDSET *stcpu = NULL, *stclients = NULL, *streqs = NULL, *stbytes = NULL;
@@ -55,6 +56,10 @@ void *proc_main(void *ptr)
                
                // BEGIN -- the job to be done
                
+               if(!vdo_proc_interrupts) {
+                       debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_proc_interrupts().");
+                       vdo_proc_interrupts = do_proc_interrupts(rrd_update_every, usec+susec);
+               }
                if(!vdo_proc_sys_kernel_random_entropy_avail) {
                        debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_proc_sys_kernel_random_entropy_avail().");
                        vdo_proc_sys_kernel_random_entropy_avail = do_proc_sys_kernel_random_entropy_avail(rrd_update_every, usec+susec);
index e4ba2cc8f4ec89f09d99f8b06a67219619c93fc7..fa074ac13bb57c6f5bb7a13202a9701444848183 100755 (executable)
@@ -14,5 +14,6 @@ extern int do_proc_meminfo(int update_every, unsigned long long dt);
 extern int do_proc_vmstat(int update_every, unsigned long long dt);
 extern int do_proc_net_rpc_nfsd(int update_every, unsigned long long dt);
 extern int do_proc_sys_kernel_random_entropy_avail(int update_every, unsigned long long dt);
+extern int do_proc_interrupts(int update_every, unsigned long long dt);
 
 #endif /* NETDATA_PLUGIN_PROC_H */
diff --git a/src/proc_interrupts.c b/src/proc_interrupts.c
new file mode 100755 (executable)
index 0000000..4baecf0
--- /dev/null
@@ -0,0 +1,147 @@
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "config.h"
+#include "procfile.h"
+#include "rrd.h"
+#include "plugin_proc.h"
+#include "log.h"
+
+#define MAX_INTERRUPTS 256
+#define MAX_INTERRUPT_CPUS 256
+#define MAX_INTERRUPT_NAME 20
+
+struct interrupt {
+       int used;
+       char *id;
+       char *name;
+       unsigned long long value[MAX_INTERRUPT_CPUS];
+       unsigned long long total;
+};
+
+int do_proc_interrupts(int update_every, unsigned long long dt) {
+       static procfile *ff = NULL;
+       static int cpus = -1, do_per_core = -1;
+
+       if(dt) {};
+
+       if(do_per_core == -1) do_per_core = config_get_boolean("plugin:proc:/proc/interrupts", "interrupts per core", 1);
+
+       if(!ff) ff = procfile_open("/proc/interrupts", " \t", PROCFILE_FLAG_DEFAULT);
+       if(!ff) return 1;
+
+       ff = procfile_readall(ff);
+       if(!ff) return 0; // we return 0, so that we will retry to open it next time
+
+       uint32_t lines = procfile_lines(ff), l;
+       uint32_t words = procfile_linewords(ff, 0), w;
+
+       // find how many CPUs are there
+       if(cpus == -1) {
+               cpus = 0;
+               for(w = 0; w < words ; w++) {
+                       if(strncmp(procfile_lineword(ff, 0, w), "CPU", 3) == 0)
+                               cpus++;
+               }
+
+               if(cpus > MAX_INTERRUPT_CPUS) cpus = MAX_INTERRUPT_CPUS;
+       }
+
+       if(!cpus) {
+               error("PLUGIN: PROC_INTERRUPTS: Cannot find the number of CPUs in /proc/interrupts");
+               return 1;
+       }
+
+       // allocate the size we need;
+       struct interrupt irrs[lines];
+       irrs[0].used = 0;
+
+       // loop through all lines
+       for(l = 1; l < lines ;l++) {
+               struct interrupt *irr = &irrs[l];
+               irr->used = 0;
+               irr->total = 0;
+
+               words = procfile_linewords(ff, l);
+               if(!words) continue;
+
+               irr->id = procfile_lineword(ff, l, 0);
+               if(!irr->id || !irr->id[0]) continue;
+
+               if(irr->id[strlen(irr->id) - 1] == ':')
+                       irr->id[strlen(irr->id) - 1] = '\0';
+
+               int c;
+               for(c = 0; c < cpus ;c++) {
+                       if((c + 1) < (int)words)
+                               irr->value[c] = strtoull(procfile_lineword(ff, l, (uint32_t)(c + 1)), NULL, 10);
+                       else
+                               irr->value[c] = 0;
+
+                       irr->total += irr->value[c];
+               }
+
+               if(isdigit(irr->id[0]) && (uint32_t)(cpus + 2) < words) {
+                       irr->name = procfile_lineword(ff, l, words - 1);
+               }
+               else
+                       irr->name = irr->id;
+
+               irr->used = 1;
+       }
+
+       RRDSET *st;
+
+       // --------------------------------------------------------------------
+
+       st = rrdset_find_bytype("system", "interrupts");
+       if(!st) {
+               st = rrdset_create("system", "interrupts", NULL, "system", "System interrupts", "interrupts/s", 1000, update_every, RRDSET_TYPE_STACKED);
+
+               for(l = 0; l < lines ;l++) {
+                       if(!irrs[l].used) continue;
+                       rrddim_add(st, irrs[l].id, irrs[l].name, 1, update_every, RRDDIM_INCREMENTAL);
+               }
+       }
+       else rrdset_next(st);
+
+       for(l = 0; l < lines ;l++) {
+               if(!irrs[l].used) continue;
+               rrddim_set(st, irrs[l].id, irrs[l].total);
+       }
+       rrdset_done(st);
+
+       if(do_per_core) {
+               int c;
+
+               for(c = 0; c < cpus ; c++) {
+                       char id[256];
+                       snprintf(id, 256, "cpu%d_interrupts", c);
+
+                       st = rrdset_find_bytype("cpu", id);
+                       if(!st) {
+                               char name[256], title[256];
+                               snprintf(name, 256, "cpu%d_interrupts", c);
+                               snprintf(title, 256, "CPU%d Interrupts", c);
+                               st = rrdset_create("cpu", id, name, "cpu", title, "interrupts/s", 2000 + c, update_every, RRDSET_TYPE_STACKED);
+
+                               for(l = 0; l < lines ;l++) {
+                                       if(!irrs[l].used) continue;
+                                       rrddim_add(st, irrs[l].id, irrs[l].name, 1, update_every, RRDDIM_INCREMENTAL);
+                               }
+                       }
+                       else rrdset_next(st);
+
+                       for(l = 0; l < lines ;l++) {
+                               if(!irrs[l].used) continue;
+                               rrddim_set(st, irrs[l].id, irrs[l].value[c]);
+                       }
+                       rrdset_done(st);
+               }
+       }
+
+       return 0;
+}