Class: Metrix::Graphite
- Inherits:
- 
      Object
      
        - Object
- Metrix::Graphite
 
- Defined in:
- lib/metrix/graphite.rb
Instance Attribute Summary collapse
- 
  
    
      #host  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute host. 
- 
  
    
      #port  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute port. 
Instance Method Summary collapse
- #<<(metric) ⇒ Object
- #buffers ⇒ Object
- #flush ⇒ Object
- 
  
    
      #initialize(host, port = 2003)  ⇒ Graphite 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Graphite. 
- #logger ⇒ Object
Constructor Details
#initialize(host, port = 2003) ⇒ Graphite
Returns a new instance of Graphite.
| 8 9 10 11 | # File 'lib/metrix/graphite.rb', line 8 def initialize(host, port = 2003) @host = host @port = port end | 
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
| 6 7 8 | # File 'lib/metrix/graphite.rb', line 6 def host @host end | 
#port ⇒ Object (readonly)
Returns the value of attribute port.
| 6 7 8 | # File 'lib/metrix/graphite.rb', line 6 def port @port end | 
Instance Method Details
#<<(metric) ⇒ Object
| 13 14 15 16 17 18 19 | # File 'lib/metrix/graphite.rb', line 13 def <<(metric) metric.metrics.each do |m| logger.debug "adding #{m.to_graphite}" buffers << m.to_graphite flush if buffers.count > 90 end end | 
#buffers ⇒ Object
| 21 22 23 | # File 'lib/metrix/graphite.rb', line 21 def buffers @buffers ||= [] end | 
#flush ⇒ Object
| 25 26 27 28 29 30 31 32 33 34 35 36 | # File 'lib/metrix/graphite.rb', line 25 def flush if buffers.empty? logger.info "nothing to send" return end started = Time.now Socket.tcp(@host, @port) do |socket| socket.puts(buffers.join("\n")) end logger.info "sent #{buffers.count} in %.06fs" % [Time.now - started] buffers.clear end |