sensu / system-profile-linux

A Sensu plugin for collecting system resource metrics from the procfile system, with the aim to provide a Sensu-native alternative to Collectd's built-in system resource telemetry.
MIT License
3 stars 3 forks source link

Feature: synthetically generate cpu state percentages as metrics #10

Open jspaleta opened 4 years ago

jspaleta commented 4 years ago

/proc/stat provides raw timing information concerning cpu state, that take some processing to be useful.

system-profile-linux could be updated to operate in a way to provide cpu utilization metrics by taking a two separate snapshots of /proc/stat a set interval a part and intepreting the cpu state information increases as a percentage of the available interval... once the clock_tick freqency of the system is known from sysconf lookup (see other issue on that)

Pseudo-math for calculating percentage of time in system state for interval t_0 to t_1 (cpu.system_1 - cpu.system_0) / (clock_tick_frequency * (t_1 - t_0))

clock_tick_frequency is commonly 100 Hz, but this cannot be assumed, must check with sysconf on the value being use by the running kernel.

default interval t_1 - t_0 could 1 second

This calculation could be done for all the cpu timing metrics currently being reported to extend the profile information provide.

asachs01 commented 4 years ago

@jspaleta I've got a feeling that we could try and refactor this plugin to use Gopsutil since the library already does the heavy lifting of generating percentages https://godoc.org/github.com/shirou/gopsutil/cpu#Percent. I actually think it might be ideal to do this since we could just use this one library and generate quite a bit more metric data