Class: Drone::Interfaces::Collectd
- Inherits:
-
Base
- Object
- Base
- Drone::Interfaces::Collectd
- Defined in:
- lib/drone_collectd/collectd.rb
Overview
Constant Summary collapse
- NAME_FORMAT =
1.9 only … NAME_FORMAT = %r(?<plugin>w+)(:(?<plugin_instance>w+))?/(?<type>w+)(:(?<type_instance>w+))?
%r{(\w+)(?::(\w+))?/(\w+)(?::(\w+))?}
Instance Method Summary collapse
-
#initialize(period, args = {}) ⇒ Collectd
constructor
Instantiate a collectd interface.
- #output ⇒ Object
Constructor Details
#initialize(period, args = {}) ⇒ Collectd
Instantiate a collectd interface
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/drone_collectd/collectd.rb', line 29 def initialize(period, args = {}) super(period) @hostname = args.delete(:hostname) @address = args.delete(:address) || '127.0.0.1' @port = args.delete(:port) || 25826 @reported_percentiles = args.delete(:percentiles) @socket = EM::open_datagram_socket('0.0.0.0', nil) unless args.empty? raise ArgumentError, "unknown keys: #{args.keys}" end end |
Instance Method Details
#output ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/drone_collectd/collectd.rb', line 42 def output Drone::each_metric do |m| # parse the name if NAME_FORMAT.match(m.name) # build the packet data = DroneCollectd::CollectdPacket.new data.host = @hostname data.time = Time.now.to_i data.interval = @period data.plugin = $1.to_s data.plugin_instance = $2.to_s data.type = $3.to_s data.type_instance = $4.to_s case m when Metrics::Counter data.add_value(:counter, m.value ) when Metrics::Gauge data.add_value(:gauge, m.value ) when Metrics::Meter # mean:GAUGE:U:U, rate1:GAUGE:U:U, rate5:GAUGE:U:U, rate15:GAUGE:U:U data.add_value(:gauge, m.mean_rate ) data.add_value(:gauge, m.one_minute_rate ) data.add_value(:gauge, m.five_minutes_rate ) data.add_value(:gauge, m.fifteen_minutes_rate ) when Metrics::Timer, Metrics::Histogram # min:GAUGE:0:U, max:GAUGE:0:U, mean:GAUGE:0:U, stddev:GAUGE:U:U, median:GAUGE:0:U, p75:GAUGE:0:U, p95:GAUGE:0:U data.add_value(:gauge, m.min ) data.add_value(:gauge, m.max ) data.add_value(:gauge, m.mean ) data.add_value(:gauge, m.stdDev ) percs = m.percentiles( *@reported_percentiles ) percs.each do |p| data.add_value(:gauge, p ) end end # and send it @socket.send_datagram(data.build_packet, @address, @port) else puts "Metric with incorrect name ignored: #{m.name}" end end end |