Class: OpenTsdb::Server
- Inherits:
-
Object
- Object
- OpenTsdb::Server
- Includes:
- HTTParty
- Defined in:
- lib/psc/opentsdb.rb
Instance Attribute Summary collapse
-
#port ⇒ Object
Returns the value of attribute port.
-
#server_url ⇒ Object
Returns the value of attribute server_url.
Instance Method Summary collapse
- #create_metric(metric) ⇒ Object
-
#initialize(server_url, port = 4242) ⇒ Server
constructor
A new instance of Server.
- #put(data_points) ⇒ Object
- #suggest(type, query = nil, max = 1000) ⇒ Object
Constructor Details
#initialize(server_url, port = 4242) ⇒ Server
Returns a new instance of Server.
10 11 12 13 14 |
# File 'lib/psc/opentsdb.rb', line 10 def initialize(server_url,port = 4242) @server_url = server_url @port = port self.class.base_uri @server_url + ":" + @port.to_s end |
Instance Attribute Details
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/psc/opentsdb.rb', line 8 def port @port end |
#server_url ⇒ Object
Returns the value of attribute server_url.
8 9 10 |
# File 'lib/psc/opentsdb.rb', line 8 def server_url @server_url end |
Instance Method Details
#create_metric(metric) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/psc/opentsdb.rb', line 32 def create_metric(metric) data = Hash.new data['metric'] = [metric] response = self.class.post('/api/uid/assign',body: data.to_json) puts '***' puts response.parsed_response.to_s if response.code == 400 raise MetricCreationError , metric + " could not be created. " + response.parsed_response['metric_errors'][metric].to_s return elsif response.code != 200 raise MetricCreationError , metric + " could not be created. Unknown Error" return end response end |
#put(data_points) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/psc/opentsdb.rb', line 48 def put(data_points) # data_points = array of data point objects data = Array.new data_points.each do |dp| data.push(dp.to_hash) end response = self.class.post('/api/put', body: data.to_json) end |
#suggest(type, query = nil, max = 1000) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/psc/opentsdb.rb', line 16 def suggest(type,query=nil,max=1000) # type must be one of metrics, tagk, tagv # query matches entire strings to front of stored data # max is max results returned data = Hash.new data['type'] = type unless query.nil? data['q'] = query end data['max'] = max response = self.class.post('/api/suggest',body: data.to_json) return response.parsed_response end |