sensu-plugins / sensu-plugins-docker

This plugin provides native Docker instrumentation for monitoring and metrics collection, including: container status, container number, and container metrics via `docker ps`.
http://sensu-plugins.io
MIT License
35 stars 57 forks source link

Error when a container is Restarting and option -P is used in the metric-container-stats.rb #84

Open asanchez1978 opened 5 years ago

asanchez1978 commented 5 years ago

If the option -P is used in the metric-container-stats.rb and one of the docker containers has the state Restarting, an error appears when Sensu executes the plugin. Ex: /opt/sensu/embedded/bin/metrics-docker-stats.rb -H /var/run/docker.sock -n -P

Error:

mongo-historico-conf.id 5b90c05015de78d7f5489d142f74998a5a6250d13b455e985bde12450e3596a6 1566806214
Check failed to run: undefined method `-' for nil:NilClass, ["/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-docker-3.2.0/bin/metrics-docker-stats.rb:212:in `calculate_cpu_percent'", "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-docker-3.2.0/bin/metrics-docker-stats.rb:153:in `output_stats'", "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-docker-3.2.0/bin/metrics-docker-stats.rb:135:in `block in run'", "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-docker-3.2.0/bin/metrics-docker-stats.rb:121:in `each'", "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-docker-3.2.0/bin/metrics-docker-stats.rb:121:in `run'", "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugin-2.7.1/lib/sensu-plugin/cli.rb:57:in `block in <class:CLI>'"]

If you stop/down this container, the Sensu plugin works fine.

It's possible to solve it??