Class: CollectdServer::Connection
- Inherits:
-
Object
- Object
- CollectdServer::Connection
- Defined in:
- lib/collectd_server.rb
Instance Method Summary collapse
-
#initialize(service_uri) ⇒ Connection
constructor
A new instance of Connection.
- #receive_data(data) ⇒ Object
Constructor Details
#initialize(service_uri) ⇒ Connection
Returns a new instance of Connection.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/collectd_server.rb', line 38 def initialize(service_uri) @http = Resourceful::HttpAccessor.new @http.add_authenticator(Resourceful::SSBEAuthenticator.new('admin', 'admin')) resp = @http.resource(service_uri).get(:accept => 'application/csv') bulk_datapoint_href = nil FasterCSV.parse(resp.body, :headers => true) do |row| if row['name'] == 'BulkCreateDatapoints' bulk_datapoint_href = row['resource_href'] end end @datapoint_resource = @http.resource(bulk_datapoint_href) end |
Instance Method Details
#receive_data(data) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/collectd_server.rb', line 54 def receive_data(data) packet = Packet.new(data) dps = packet.to_datapoints csv = FasterCSV.generate do |csv| dps.each do |dp| csv << dp.to_a end end @datapoint_resource.post(csv, :content_type => 'text/csv') end |