metrics-http-json-deep.rb not working
I've been having a difficult time with the metrics-http-json-deep.rb check. I am trying to use it to collect metrics reported in JSON over HTTP in order to send them to graphite. When I run it against a simple JSON message with just two key/value pairs (like http://echo.jsontest.com/key/value/one/two), I get the following error:
Check failed to run: undefined method each' for nil:NilClass, ["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-http-1.0.0/bin/metrics-http-json-deep.rb:81:in deep_value'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-http-1.0.0/bin/metrics-http-json-deep.rb:119:in run'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.2.0/lib/sensu-plugin/cli.rb:56:in block in <class:CLI>'"]
With more complex JSON messages, such as the output I'm actually trying to record, I get this error:
Check failed to run: no implicit conversion of Regexp into String, ["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-http-1.0.0/bin/metrics-http-json-deep.rb:82:in tr'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-http-1.0.0/bin/metrics-http-json-deep.rb:82:in block in deep_value'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-http-1.0.0/bin/metrics-http-json-deep.rb:81:in each'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-http-1.0.0/bin/metrics-http-json-deep.rb:81:in deep_value'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-http-1.0.0/bin/metrics-http-json-deep.rb:119:in run'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.2.0/lib/sensu-plugin/cli.rb:56:in block in <class:CLI>'"]
I installed the check using sensu-install, if that helps. Any idea what the issue could be here? Would greatly appreciate any help debugging this.
For anyone else who is googling this:
Source:
curl -s http://0.0.0.0:9292/health| python -mjson.tool
{
"queue_depth": {
"connector_worker_pool": 0,
"publisher_pool": 0,
"status_updater_pool": 0
}
}
Error:
metrics-http-json-deep.rb --url http://0.0.0.0:9292/health
Check failed to run: undefined method `each' for nil:NilClass, ["/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-http-1.0.0/bin/metrics-http-json-deep.rb:81:in `deep_value'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugins-http-1.0.0/bin/metrics-http-json-deep.rb:129:in `run'", "/opt/sensu/embedded/lib/ruby/gems/2.3.0/gems/sensu-plugin-1.3.0/lib/sensu-plugin/cli.rb:57:in `block in <class:CLI>'"]
Solution:
metrics-http-json-deep.rb --port 9292 --path health --root 'queue_depth'
ubuntu.json.connector_worker_pool 0 1470950544
ubuntu.json.publisher_pool 0 1470950544
ubuntu.json.status_updater_pool 0 1470950544
Is this still an issue?
@ghettodev could you put together a pr to document this useage?