Class: GraphiteClient::EventReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/graphite_client/event_reporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(graphite_server_events_url, opts = {}) ⇒ EventReporter

Returns a new instance of EventReporter.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/graphite_client/event_reporter.rb', line 7

def initialize(graphite_server_events_url, opts={})
  uri   = URI(graphite_server_events_url)
  @http = Net::HTTP.new(uri.host, uri.port)
  @req  = Net::HTTP::Post.new(uri.request_uri)

  @http.use_ssl = true if uri.scheme == 'https'

  if opts[:basic_auth]
    username = opts[:basic_auth][:username]
    password = opts[:basic_auth][:password]
    @req.basic_auth(username, password)
  end
end

Instance Method Details

#report(event = {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/graphite_client/event_reporter.rb', line 21

def report(event={})
  event[:tags] = Array(event[:tags]).join(',')
  # data should be a string.
  event[:data] = event[:data].is_a?(String) ? event[:data] : event[:data].to_json
  @req.body = event.to_json
  @http.request(@req)
end