Class: Sensu::Plugin::Metric::CLI
- Defined in:
- lib/sensu-plugin/metric/cli.rb
Defined Under Namespace
Classes: Dogstatsd, Generic, Graphite, Influxdb, JSON, Statsd
Instance Attribute Summary
Attributes inherited from CLI
Instance Method Summary collapse
-
#to_dogstatsd(*args) ⇒ String
Outputs metrics using the DogStatsd datagram format.
-
#to_graphite(*args) ⇒ String
Outputs metrics using the Statsd datagram format.
-
#to_influxdb(*args) ⇒ String
Outputs metrics using the InfluxDB line protocol format.
-
#to_json(obj = nil) ⇒ String
Outputs metrics using raw json format.
-
#to_statsd(*args) ⇒ String
Outputs metrics using the Statsd datagram format.
Methods inherited from CLI
#initialize, method_added, #output, #run
Constructor Details
This class inherits a constructor from Sensu::Plugin::CLI
Instance Method Details
#to_dogstatsd(*args) ⇒ String
the argument order should be: ‘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 comma separated key:value string `tag1:value1,tag2:value2`
Outputs metrics using the DogStatsd datagram format
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sensu-plugin/metric/cli.rb', line 68 def to_dogstatsd(*args) return if args.join.empty? if args[0].is_a?(Exception) || args[1].nil? puts args[0].to_s else type = args[2] || 'kv' = args[3] ? "##{args[3]}" : nil puts [args[0..1].join(':'), type, ].compact.join('|') end end |
#to_graphite(*args) ⇒ String
the argument order should be: ‘metric_path`: Mandatory, name for the metric, `value`: Mandatory, metric value `timestamp`: Optional, unix timestamp, defaults to current time
Outputs metrics using the Statsd datagram format
31 32 33 34 35 36 37 38 39 |
# File 'lib/sensu-plugin/metric/cli.rb', line 31 def to_graphite(*args) return if args.join.empty? if args[0].is_a?(Exception) || args[1].nil? puts args[0].to_s else args[2] ||= Time.now.to_i puts args[0..2].join("\s") end end |
#to_influxdb(*args) ⇒ String
the argument order should be: ‘measurement_name`: Mandatory, name for the InfluxDB measurement, `fields`: Mandatory, either an integer or a comma separated key=value string `field1=value1,field2=value2` `tags`: Optional, a comma separated key=value string `tag1=value1,tag2=value2` `timestamp`: Optional, unix timestamp, defaults to current time
Outputs metrics using the InfluxDB line protocol format
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/sensu-plugin/metric/cli.rb', line 88 def to_influxdb(*args) return if args.join.empty? if args[0].is_a?(Exception) || args[1].nil? puts args[0].to_s else fields = if args[1].is_a?(Integer) "value=#{args[1]}" else args[1] end measurement = [args[0], args[2]].compact.join(',') ts = args[3] || Time.now.to_i puts [measurement, fields, ts].join(' ') end end |
#to_json(obj = nil) ⇒ String
Outputs metrics using raw json format
14 15 16 17 18 19 20 21 |
# File 'lib/sensu-plugin/metric/cli.rb', line 14 def to_json(obj = nil) if obj.is_a?(String) || obj.is_a?(Exception) puts obj.to_s elsif obj.is_a?(Hash) obj['timestamp'] ||= Time.now.to_i puts ::JSON.generate(obj) end end |
#to_statsd(*args) ⇒ String
the argument order should be: ‘metric_name`: Mandatory, name for the metric, `value`: Mandatory, metric value `type`: Optional, metric type- `c` for counter, `g` for gauge, `ms` for timer, `s` for set
Outputs metrics using the Statsd datagram format
49 50 51 52 53 54 55 56 57 |
# File 'lib/sensu-plugin/metric/cli.rb', line 49 def to_statsd(*args) return if args.join.empty? if args[0].is_a?(Exception) || args[1].nil? puts args[0].to_s else type = args[2] || 'kv' puts [args[0..1].join(':'), type].join('|') end end |