sensu-plugins / sensu-plugin

A framework for writing Sensu plugins & handlers with Ruby.
http://sensuapp.org
MIT License
126 stars 117 forks source link

add multiple metrics output format support #37 #185

Closed bergerx closed 6 years ago

bergerx commented 6 years ago

This will add support for multiple metric output formats within the same class.

Description

This changes moves the different output formats into a base metrics cli class and let implementers to choose the output format on runtime.

Motivation and Context

We have been struggling to use various sensu metrics plugin scripts since most of the existing plugins are generating metrics in graphite format and this format is not easy to map to other metric storage architectures with tags that can't be known ahead of time. So we've been either forced to (re)implement copies of the graphite metrics collector scripts in our choice of metrics storage or maintain mappings for grafana metric path to other metrics storage option. E.g. We've been using influxdb templates to map grafana metric path to influxdb measurement, tags, fields and trying to maintain the mapping templates is not optimal for long term operational goals.

Expectation is to let the graphite specific plugins to start using the generic metrics class and start supporting other metric formats without having to copy the metric collection logic. The output function calls in metric collection scripts needs to decorated with a better metadata for this change.

This issue has been previously discussed in #37, and this is just an initial implementation for the idea there. And one of the main blocking issues (chef/mixlib-cli#13) seems to be solved after that ticket is open.

How Has This Been Tested?

Here are the test results, I also added some tests to cpover the new feature:

sensu-plugin: (generic-metrics u=) $ bundle exec rake
Running RuboCop...
Inspecting 34 files
..................................

34 files inspected, no offenses detected
Run options: --seed 60796

# Running:

......................................................

Finished in 8.552982s, 6.3136 runs/s, 16.6024 assertions/s.

54 runs, 142 assertions, 0 failures, 0 errors, 0 skips
sensu-plugin: (generic-metrics u=) $ bundle exec test/external/generic-metrics  --metric_format graphite
metric.name 0 1517963264
metric.name 1 1517963264
graphite.metric.path 2 1517963264
metric.name 3 1517963264
metric.name 4 1517963264
metric.name 5 1517963264
metric.name 6 1517963264
metric.name 7 1517963264
sensu-plugin: (generic-metrics u=) $ bundle exec test/external/generic-metrics  --metric_format dogstatsd
metric.name:0|kv|#
metric.name:1|kv|#env:prod,location:us-midwest
metric.name:2|kv|#
statsd.metric.name:3|s|#
statsd.metric.name:4|m|#
dogstatsd.metric.name:5|kv|#
metric.name:6|kv|#
metric.name:7|kv|#
sensu-plugin: (generic-metrics u=) $ bundle exec test/external/generic-metrics  --metric_format influxdb
GenericTestMetric, metric.name=0 1517963271
GenericTestMetric,env=prod,location=us-midwest metric.name=1 1517963271
GenericTestMetric, metric.name=2 1517963271
GenericTestMetric, metric.name=3 1517963271
GenericTestMetric, metric.name=4 1517963271
GenericTestMetric, metric.name=5 1517963271
influxdb.measurement, metric.name=6 1517963271
GenericTestMetric, influxdb.field=7 1517963271
sensu-plugin: (generic-metrics u=) $ 

Types of changes

Checklist:

Known Caveats

majormoses commented 6 years ago

released: https://rubygems.org/gems/sensu-plugin/versions/2.4.0