sensu-plugins / sensu-plugins-cpu-checks

This plugin provides native CPU instrumentation for monitoring and metrics collection, including: CPU usage and metrics for user, nice, system, idle, iowait, irq, softirq, steal, and guest.
http://sensu-plugins.io
MIT License
13 stars 34 forks source link

Wrong type being set for --proc-path long option #23

Closed envintus closed 7 years ago

envintus commented 7 years ago

The --proc-path long option is being set as a float instead of a string. The default for this option works fine, but when a user supplied value is passed that value is then converted to a float. The value of config[:proc_path] then becomes 0.0.

Assuming a scenario where you are running the Sensu client as a container with the host /proc/ file system mounted at /rootfs/proc, the following output is the error produced:

/opt/sensu/embedded/bin/check-cpu.rb --proc-path=/rootfs/proc
Check failed to run: No such file or directory @ rb_sysopen - 0.0/stat, ["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb:71:in `initialize'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb:71:in `open'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb:71:in `acquire_cpu_stats'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-cpu-checks-1.0.0/bin/check-cpu.rb:79:in `run'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.4.4/lib/sensu-plugin/cli.rb:58:in `block in <class:CLI>'"]

In the above output you can see what should be /rootfs/proc/stat is 0.0/stat, because that user input is being converted to a float.

majormoses commented 7 years ago

closed by #24

bimlendu commented 7 years ago

@majormoses This change is also needed for metrics-cpu.rb and metrics-cpu-pcnt-usage.rb.

majormoses commented 7 years ago

@bimlendu can you open a pr for the same?