10 #include "appconfig.h"
13 #include "plugin_proc.h"
16 #define MAX_INTERRUPTS 256
17 #define MAX_INTERRUPT_CPUS 256
18 #define MAX_INTERRUPT_NAME 20
24 unsigned long long value[MAX_INTERRUPT_CPUS];
25 unsigned long long total;
28 int do_proc_interrupts(int update_every, unsigned long long dt) {
29 static procfile *ff = NULL;
30 static int cpus = -1, do_per_core = -1;
34 if(do_per_core == -1) do_per_core = config_get_boolean("plugin:proc:/proc/interrupts", "interrupts per core", 0);
37 char filename[FILENAME_MAX + 1];
38 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/interrupts");
39 ff = procfile_open(config_get("plugin:proc:/proc/interrupts", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
43 ff = procfile_readall(ff);
44 if(!ff) return 0; // we return 0, so that we will retry to open it next time
46 uint32_t lines = procfile_lines(ff), l;
47 uint32_t words = procfile_linewords(ff, 0), w;
49 // find how many CPUs are there
52 for(w = 0; w < words ; w++) {
53 if(strncmp(procfile_lineword(ff, 0, w), "CPU", 3) == 0)
57 if(cpus > MAX_INTERRUPT_CPUS) cpus = MAX_INTERRUPT_CPUS;
61 error("PLUGIN: PROC_INTERRUPTS: Cannot find the number of CPUs in /proc/interrupts");
65 // allocate the size we need;
66 struct interrupt irrs[lines];
69 // loop through all lines
70 for(l = 1; l < lines ;l++) {
71 struct interrupt *irr = &irrs[l];
75 words = procfile_linewords(ff, l);
78 irr->id = procfile_lineword(ff, l, 0);
79 if(!irr->id || !irr->id[0]) continue;
81 if(irr->id[strlen(irr->id) - 1] == ':')
82 irr->id[strlen(irr->id) - 1] = '\0';
85 for(c = 0; c < cpus ;c++) {
86 if((c + 1) < (int)words)
87 irr->value[c] = strtoull(procfile_lineword(ff, l, (uint32_t)(c + 1)), NULL, 10);
91 irr->total += irr->value[c];
94 if(isdigit(irr->id[0]) && (uint32_t)(cpus + 2) < words) {
95 irr->name = procfile_lineword(ff, l, words - 1);
105 // --------------------------------------------------------------------
107 st = rrdset_find_bytype("system", "interrupts");
109 st = rrdset_create("system", "interrupts", NULL, "system", "System interrupts", "interrupts/s", 1000, update_every, RRDSET_TYPE_STACKED);
111 for(l = 0; l < lines ;l++) {
112 if(!irrs[l].used) continue;
113 rrddim_add(st, irrs[l].id, irrs[l].name, 1, update_every, RRDDIM_INCREMENTAL);
116 else rrdset_next(st);
118 for(l = 0; l < lines ;l++) {
119 if(!irrs[l].used) continue;
120 rrddim_set(st, irrs[l].id, irrs[l].total);
127 for(c = 0; c < cpus ; c++) {
129 snprintf(id, 256, "cpu%d_interrupts", c);
131 st = rrdset_find_bytype("cpu", id);
133 char name[256], title[256];
134 snprintf(name, 256, "cpu%d_interrupts", c);
135 snprintf(title, 256, "CPU%d Interrupts", c);
136 st = rrdset_create("cpu", id, name, "cpu", title, "interrupts/s", 2000 + c, update_every, RRDSET_TYPE_STACKED);
138 for(l = 0; l < lines ;l++) {
139 if(!irrs[l].used) continue;
140 rrddim_add(st, irrs[l].id, irrs[l].name, 1, update_every, RRDDIM_INCREMENTAL);
143 else rrdset_next(st);
145 for(l = 0; l < lines ;l++) {
146 if(!irrs[l].used) continue;
147 rrddim_set(st, irrs[l].id, irrs[l].value[c]);