Class: Naplug::Helpers::ENGraphite::Client
- Inherits:
-
Object
- Object
- Naplug::Helpers::ENGraphite::Client
- Defined in:
- lib/naplug/helpers.rb
Instance Attribute Summary collapse
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
Instance Method Summary collapse
- #flush!(options = { :timeout => 3}) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #metric(path, value, time = Time.now) ⇒ Object
- #metrics! ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
60 61 62 63 64 65 66 |
# File 'lib/naplug/helpers.rb', line 60 def initialize() raise ArgumentError, 'missing graphite server address' if [:graphite].nil? @graphite = [:graphite] @port = [:port].nil? ? 2003 : [:port].to_i @prefix = [:prefix].nil? ? '' : [:prefix] @metrics = [] end |
Instance Attribute Details
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
58 59 60 |
# File 'lib/naplug/helpers.rb', line 58 def metrics @metrics end |
Instance Method Details
#flush!(options = { :timeout => 3}) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/naplug/helpers.rb', line 79 def flush!( = { :timeout => 3}) begin Timeout.timeout([:timeout]) do s = TCPSocket.open(@graphite,@port) @metrics.each do |metric| metric = "#{@prefix}.#{metric.to_s}\n" s.write metric end s.close end rescue Timeout::Error => e raise Naplug::Error, "graphite timeout (#{options[:timeout]}s)" rescue Errno::ECONNREFUSED, SocketError => e raise Naplug::Error, 'graphite socket error' end end |
#metric(path, value, time = Time.now) ⇒ Object
68 69 70 |
# File 'lib/naplug/helpers.rb', line 68 def metric path, value, time = Time.now @metrics.push(Metric.new(path,value,time)) end |
#metrics! ⇒ Object
72 73 74 75 76 77 |
# File 'lib/naplug/helpers.rb', line 72 def metrics! @metrics.each do |metric| metric = "#{@prefix}.#{metric.to_s}\n" print metric end end |