add variable system.cpu.processors for alarms; fixes #3003 (#4155)
Costa Tsaousis committed
Sep 12, 2018 at 14:28 UTC
1ef5cd1bb3000537c8bf126b698f8a5a48e6b97b
1 file changed
+9
src/proc_stat.c
+9
@@ -122,6 +122,8 @@ int do_proc_stat(int update_every, usec_t dt) {
122
static int do_cpu = -1, do_cpu_cores = -1, do_interrupts = -1, do_context = -1, do_forks = -1, do_processes = -1, do_core_throttle_count = -1, do_package_throttle_count = -1, do_scaling_cur_freq = -1;
123
static uint32_t hash_intr, hash_ctxt, hash_processes, hash_procs_running, hash_procs_blocked;
124
static char *core_throttle_count_filename = NULL, *package_throttle_count_filename = NULL, *scaling_cur_freq_filename = NULL;
125
+ static RRDSETVAR *cpus_var = NULL;
126
+ size_t cores_found = (size_t)processors;
127
128
if(unlikely(do_cpu == -1)) {
129
do_cpu = config_get_boolean("plugin:proc:/proc/stat", "cpu utilization", CONFIG_BOOLEAN_YES);
@@ -197,6 +199,7 @@ int do_proc_stat(int update_every, usec_t dt) {
199
}
200
201
size_t core = (row_key[3] == '\0') ? 0 : str2ul(&row_key[3]) + 1;
202
+ if(core > 0) cores_found = core;
203
204
if(likely((core == 0 && do_cpu) || (core > 0 && do_cpu_cores))) {
205
char *id;
@@ -309,6 +312,9 @@ int do_proc_stat(int update_every, usec_t dt) {
312
cpu_chart->rd_iowait = rrddim_add(cpu_chart->st, "iowait", NULL, multiplier, divisor, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
313
cpu_chart->rd_idle = rrddim_add(cpu_chart->st, "idle", NULL, multiplier, divisor, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
314
rrddim_hide(cpu_chart->st, "idle");
315
+
316
+ if(unlikely(core == 0 && cpus_var == NULL))
317
+ cpus_var = rrdsetvar_custom_chart_variable_create(cpu_chart->st, "processors");
318
}
319
else rrdset_next(cpu_chart->st);
320
@@ -554,5 +560,8 @@ int do_proc_stat(int update_every, usec_t dt) {
560
}
561
}
562
563
+ if(cpus_var)
564
+ rrdsetvar_custom_chart_variable_set(cpus_var, cores_found);
565
+
566
return 0;
567
}