Class: Nrcmd::Server::Metrics

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#get(id) ⇒ Object



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

def get(id)
  uri = URL + "/applications/#{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(id) ⇒ Object



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

def list(id)
  uri = URL + "/servers/#{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