Class: Sensu::Plugin::Metric::CLI::Generic
- Inherits:
-
Sensu::Plugin::Metric::CLI
- Object
- CLI
- Sensu::Plugin::Metric::CLI
- Sensu::Plugin::Metric::CLI::Generic
- Defined in:
- lib/sensu-plugin/metric/cli.rb
Instance Attribute Summary
Attributes inherited from CLI
Instance Method Summary collapse
-
#output(metric = {}) ⇒ String
Outputs metrics using different metric formats.
Methods inherited from Sensu::Plugin::Metric::CLI
#to_dogstatsd, #to_graphite, #to_influxdb, #to_json, #to_statsd
Methods inherited from CLI
#initialize, method_added, #run
Constructor Details
This class inherits a constructor from Sensu::Plugin::CLI
Instance Method Details
#output(metric = {}) ⇒ String
the metric could have these fields: ‘metric_name`: Mandatory, name for the metric, `value`: Mandatory, metric value `type`: Optional, metric type- `c` for counter, `g` for gauge, `ms` for timer, `h` for histogram, `s` for set `tags`: Optional, a Hash that includes all tags `timestamp`: Optional, unix timestamp, eventually defaults to output’s timestamp handling ‘graphite_metric_path`: Optional, `metric_name` will be used if not provided. `statsd_metric_name`: Optional, `metric_name` will be used if not provided. `statsd_type`: Optional. `dogstatsd_metric_name`: Optional, `statsd_metric_name` or `metric_name` will be used if not provided. `dogstatsd_type`: Optional, `statsd_type` will be used if not provided. `influxdb_measurement`: Optional, class name will be used if not provided. `influxdb_field_key`: Optional, the `metric_name` will be used if not provided.
Outputs metrics using different metric formats
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/sensu-plugin/metric/cli.rb', line 157 def output(metric = {}) return if metric.nil? || metric.empty? || metric[:value].nil? = metric[:tags] || [] case config[:metric_format] when 'json' return if metric[:value].nil? json_obj = metric[:json_obj] || { metric_name: metric[:metric_name], value: metric[:value], tags: } to_json json_obj when 'graphite' graphite_metric_path = metric[:graphite_metric_path] || metric[:metric_name] to_graphite graphite_metric_path, metric[:value], metric[:timestamp] when 'statsd' statsd_metric_name = metric[:statsd_metric_name] || metric[:metric_name] to_statsd statsd_metric_name, metric[:value], metric[:statsd_type] when 'dogstatsd' dogstatsd_metric_name = metric[:dogstatsd_metric_name] || metric[:statsd_metric_name] || metric[:metric_name] dogstatsd_type = metric[:dogstatsd_type] || metric[:statsd_type] = .map { |k, v| "#{k}:#{v}" }.join(',') to_dogstatsd dogstatsd_metric_name, metric[:value], dogstatsd_type, when 'influxdb' influxdb_measurement = metric[:influxdb_measurement] || self.class.name influxdb_field_key = metric[:influxdb_field_key] || metric[:metric_name] influxdb_field = "#{influxdb_field_key}=#{metric[:value]}" = .map { |k, v| "#{k}=#{v}" }.join(',') to_influxdb influxdb_measurement, influxdb_field, , metric[:timestamp] end end |