Module: StackDriver
- Defined in:
- lib/stackdriver.rb
Constant Summary collapse
- POST_URI =
"https://custom-gateway.stackdriver.com/v1/custom"- DELETE_URI =
"https://custom-gateway.stackdriver.com/v1/delete_custom"
Class Method Summary collapse
- .build_message(name, value, time, instance = '') ⇒ Object
- .build_multi_message(data) ⇒ Object
- .delete_metric(name, time) ⇒ Object
- .init(*args) ⇒ Object
- .post(msg, uri) ⇒ Object
- .send_metric(name, value, time, instance = '') ⇒ Object
- .send_multi_metrics(data) ⇒ Object
Class Method Details
.build_message(name, value, time, instance = '') ⇒ Object
48 49 50 51 52 53 |
# File 'lib/stackdriver.rb', line 48 def self. name, value, time, instance='' data_point = {'name' => name, 'value' => value, 'collected_at' => time} data_point.merge!('value' => value) unless value.nil? data_point.merge!('instance' => instance) unless instance.empty? {'timestamp' => Time.now.to_i, 'proto_version' => '1', 'data' => data_point} end |
.build_multi_message(data) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/stackdriver.rb', line 55 def self. data data_point = data { 'timestamp' => Time.now.to_i, 'proto_version' => '1', 'data' => data_point } end |
.delete_metric(name, time) ⇒ Object
25 26 27 28 |
# File 'lib/stackdriver.rb', line 25 def self.delete_metric name, time msg = name, nil, time post MultiJson.dump(msg), StackDriver::DELETE_URI end |
.init(*args) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/stackdriver.rb', line 7 def self.init *args if args.count > 1 puts "Customer ID is no longer needed, and will be deprecated" args.shift end @api_key = args[0] end |
.post(msg, uri) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/stackdriver.rb', line 32 def self.post msg, uri headers = {'content-type' => 'application/json', 'x-stackdriver-apikey' => @api_key} uri = URI(uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.start do |http| response = http.post(uri.path, msg, headers) if response.code != "201" raise RuntimeError, "#{response.code} - #{response.body}" end end end |
.send_metric(name, value, time, instance = '') ⇒ Object
15 16 17 18 |
# File 'lib/stackdriver.rb', line 15 def self.send_metric name, value, time, instance='' msg = name, value, time, instance post MultiJson.dump(msg), StackDriver::POST_URI end |
.send_multi_metrics(data) ⇒ Object
20 21 22 23 |
# File 'lib/stackdriver.rb', line 20 def self.send_multi_metrics data msg = data post MultiJson.dump(msg), StackDriver::POST_URI end |