Class: CdnManagerPcacheProbe::Connector
- Inherits:
-
Object
- Object
- CdnManagerPcacheProbe::Connector
- Defined in:
- lib/cdn_manager_pcache_probe/connector.rb
Instance Method Summary collapse
- #get_live_probe ⇒ Object
- #get_probe(options = {}) ⇒ Object
-
#initialize(url, options = {}) ⇒ Connector
constructor
A new instance of Connector.
- #query(options = {}) ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Connector
6 7 8 9 |
# File 'lib/cdn_manager_pcache_probe/connector.rb', line 6 def initialize(url, = {}) @url = url = end |
Instance Method Details
#get_live_probe ⇒ Object
11 12 13 |
# File 'lib/cdn_manager_pcache_probe/connector.rb', line 11 def get_live_probe get_probe(Time.now) end |
#get_probe(options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/cdn_manager_pcache_probe/connector.rb', line 15 def get_probe( = {}) probe = MultiJson.load( RestClient.get( @url, params: { source: query() } ) ) puts "Response: \n" + MultiJson.dump(probe, pretty: true) if [:debug] probe["aggregations"]["bytes_sent"]["value"] end |
#query(options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cdn_manager_pcache_probe/connector.rb', line 25 def query( = {}) interval = ([:interval] || 5).to_i delay = ([:delay] || 5).to_i volume_key_filter = "\"volume_key.raw\": \"#{options[:key]}\"" if [:key] query = %Q({ "size": 0, "query": { "filtered": { "filter": { "bool": { "must": [ { "range": { "@timestamp": { "gt": "now-#{interval + delay}m", "lt": "now-#{delay}m" } }}, { "term": { "type": "pcache" #{", " + volume_key_filter if options[:key]} } } ] } } } }, "aggs": { "bytes_sent": { "sum": { "field": "body_bytes_sent" } } } }).gsub(/\A[[:space:]]+/, '').gsub(/[[:space:]]+\z/, '').gsub(/[[:space:]]+/, ' ') puts "Query: \n" + MultiJson.dump(MultiJson.load(query), pretty: true) if [:debug] query end |