diff options
Diffstat (limited to '')
-rw-r--r-- | collectors/proc.plugin/proc_stat.c (renamed from src/proc_stat.c) | 71 |
1 files changed, 42 insertions, 29 deletions
diff --git a/src/proc_stat.c b/collectors/proc.plugin/proc_stat.c index d1aefb73e..fb77df647 100644 --- a/src/proc_stat.c +++ b/collectors/proc.plugin/proc_stat.c @@ -1,7 +1,11 @@ -#include "common.h" +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "plugin_proc.h" + +#define PLUGIN_PROC_MODULE_STAT_NAME "/proc/stat" struct per_core_single_number_file { - char found:1; + unsigned char found:1; const char *filename; int fd; collected_number value; @@ -121,6 +125,8 @@ int do_proc_stat(int update_every, usec_t dt) { 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; static uint32_t hash_intr, hash_ctxt, hash_processes, hash_procs_running, hash_procs_blocked; static char *core_throttle_count_filename = NULL, *package_throttle_count_filename = NULL, *scaling_cur_freq_filename = NULL; + static RRDVAR *cpus_var = NULL; + size_t cores_found = (size_t)processors; if(unlikely(do_cpu == -1)) { do_cpu = config_get_boolean("plugin:proc:/proc/stat", "cpu utilization", CONFIG_BOOLEAN_YES); @@ -196,6 +202,7 @@ int do_proc_stat(int update_every, usec_t dt) { } size_t core = (row_key[3] == '\0') ? 0 : str2ul(&row_key[3]) + 1; + if(core > 0) cores_found = core; if(likely((core == 0 && do_cpu) || (core > 0 && do_cpu_cores))) { char *id; @@ -236,17 +243,17 @@ int do_proc_stat(int update_every, usec_t dt) { type = "system"; context = "system.cpu"; family = id; - priority = 100; + priority = NETDATA_CHART_PRIO_SYSTEM_CPU; } else { title = "Core utilization"; type = "cpu"; context = "cpu.cpu"; family = "utilization"; - priority = 1000; + priority = NETDATA_CHART_PRIO_CPU_PER_CORE; - // FIXME: check for /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq - // FIXME: check for /sys/devices/system/cpu/cpu*/cpufreq/stats/time_in_state + // TODO: check for /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq + // TODO: check for /sys/devices/system/cpu/cpu*/cpufreq/stats/time_in_state char filename[FILENAME_MAX + 1]; struct stat stbuf; @@ -287,9 +294,9 @@ int do_proc_stat(int update_every, usec_t dt) { , context , title , "percentage" - , "proc" - , "stat" - , priority + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_STAT_NAME + , priority + core , update_every , RRDSET_TYPE_STACKED ); @@ -308,6 +315,9 @@ int do_proc_stat(int update_every, usec_t dt) { cpu_chart->rd_iowait = rrddim_add(cpu_chart->st, "iowait", NULL, multiplier, divisor, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); cpu_chart->rd_idle = rrddim_add(cpu_chart->st, "idle", NULL, multiplier, divisor, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); rrddim_hide(cpu_chart->st, "idle"); + + if(unlikely(core == 0 && cpus_var == NULL)) + cpus_var = rrdvar_custom_host_variable_create(localhost, "active_processors"); } else rrdset_next(cpu_chart->st); @@ -339,9 +349,9 @@ int do_proc_stat(int update_every, usec_t dt) { , NULL , "CPU Interrupts" , "interrupts/s" - , "proc" - , "stat" - , 900 + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_STAT_NAME + , NETDATA_CHART_PRIO_SYSTEM_INTR , update_every , RRDSET_TYPE_LINE ); @@ -371,9 +381,9 @@ int do_proc_stat(int update_every, usec_t dt) { , NULL , "CPU Context Switches" , "context switches/s" - , "proc" - , "stat" - , 800 + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_STAT_NAME + , NETDATA_CHART_PRIO_SYSTEM_CTXT , update_every , RRDSET_TYPE_LINE ); @@ -412,9 +422,9 @@ int do_proc_stat(int update_every, usec_t dt) { , NULL , "Started Processes" , "processes/s" - , "proc" - , "stat" - , 700 + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_STAT_NAME + , NETDATA_CHART_PRIO_SYSTEM_FORKS , update_every , RRDSET_TYPE_LINE ); @@ -444,9 +454,9 @@ int do_proc_stat(int update_every, usec_t dt) { , NULL , "System Processes" , "processes" - , "proc" - , "stat" - , 600 + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_STAT_NAME + , NETDATA_CHART_PRIO_SYSTEM_PROCESSES , update_every , RRDSET_TYPE_LINE ); @@ -478,9 +488,9 @@ int do_proc_stat(int update_every, usec_t dt) { , "cpu.core_throttling" , "Core Thermal Throttling Events" , "events/s" - , "proc" - , "stat" - , 5001 + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_STAT_NAME + , NETDATA_CHART_PRIO_CORE_THROTTLING , update_every , RRDSET_TYPE_LINE ); @@ -508,9 +518,9 @@ int do_proc_stat(int update_every, usec_t dt) { , "cpu.package_throttling" , "Package Thermal Throttling Events" , "events/s" - , "proc" - , "stat" - , 5002 + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_STAT_NAME + , NETDATA_CHART_PRIO_PACKAGE_THROTTLING , update_every , RRDSET_TYPE_LINE ); @@ -538,8 +548,8 @@ int do_proc_stat(int update_every, usec_t dt) { , "cpu.scaling_cur_freq" , "Per CPU Core, Current CPU Scaling Frequency" , "MHz" - , "proc" - , "stat" + , PLUGIN_PROC_NAME + , PLUGIN_PROC_MODULE_STAT_NAME , 5003 , update_every , RRDSET_TYPE_LINE @@ -553,5 +563,8 @@ int do_proc_stat(int update_every, usec_t dt) { } } + if(cpus_var) + rrdvar_custom_host_variable_set(localhost, cpus_var, cores_found); + return 0; } |