Class: Nrcmd::Apps::Hosts::Metrics

Inherits:
Thor
  • Object
show all
Defined in:
lib/nrcmd/apps/hosts/metrics.rb

Constant Summary collapse

URL =
'https://api.newrelic.com/v2'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



54
55
56
# File 'lib/nrcmd/apps/hosts/metrics.rb', line 54

def self.banner(task, namespace = false, subcommand = true)
  super
end

Instance Method Details

#get(app_id, host_id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/nrcmd/apps/hosts/metrics.rb', line 42

def get(app_id, host_id)
  uri = URL + "/applications/#{app_id}/hosts/#{host_id}/metrics/data.json"
  filter_param = ""
  filter_param << "names[]=#{options['names']}&"
  filter_param << "values[]=#{options['values']}&" if !!options['values']
  filter_param << "summarize=#{options['summarize']}&"
  filter_param << "from=#{options["from"]}&" if !!options["from"]
  filter_param << "to=#{options["to"]}&" if !!options["to"]
  res = Nrcmd::Http.get(uri, {}, filter_param)
  result = JSON.parse(res.body)
  print JSON[ result ]
end

#list(app_id, host_id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nrcmd/apps/hosts/metrics.rb', line 16

def list(app_id, host_id)
  uri = URL + "/applications/#{app_id}/hosts/#{host_id}/metrics.json"
  filter_param = ""
  options["filter"].gsub(" ", "").split(',').each do |filter|
    fkv = filter.split('=')
    filter_param << "#{fkv[0]}=#{fkv[1]}&"
  end
  res = Nrcmd::Http.get(uri, {}, filter_param)
  result = JSON.parse(res.body)
  print JSON[ result ]
end