New Relic -Web application performance monitoring ・ Performance monitoring of Web infrastructure ・ Life and death monitoring / alert It's a useful server monitoring tool that allows you to do things like **, and you can see their stats on New Relic's site. http://qiita.com/y_uuki/items/dd4fce78b1bc32b64600 However, I had to constantly look at the site to get the real-time server status, so I decided to use New Relic's API to get the server status. It seems that NewRelic's API is prepared in each language such as Python, Ruby, NodeJS, so for the time being, I tried using Python's newrelic-api.
It can be installed with pip or easy_install.
easy_install newrelic-api
Obtained API Key as Admin user. ・ Reference article http://qiita.com/CkReal/items/23a08cd8088876761911
I got the server status by referring to the official document of NewRelic API. http://new-relic-api.readthedocs.org/en/develop/ref/servers.html
When you hit the API, you can get the id, name, status, etc. of each server as an array, so this time I got the value of ** "health_status" that indicates the server status by the ** color in it.
{u'links': {u'server.alert_policy': u'/v2/alert_policies/{alert_policy_id}'},
u'servers': [{u'account_id': #{newrelic_account_id},
u'health_status': u'green',
u'host': #{newrelic_host},
u'id': #{server_id},
u'last_reported_at': u'2016-01-28T07:22:06+00:00',
u'links': {u'alert_policy': 205236},
u'name': #{server_name},
u'reporting': True,
u'summary': {u'cpu': 0.06,
u'cpu_stolen': 0.0,
u'disk_io': 0.0,
u'fullest_disk': 63.2,
u'fullest_disk_free': 7547000000,
u'memory': 63.7,
u'memory_total': 1043333120,
u'memory_used': 664797184}},
...
}]}
Python
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from newrelic_api import servers
health_statuses = []
states = servers.Servers(#{API-key}).list()["servers"]
for state in states:
if state.has_key("health_status"):
health_statuses.append(state["health_status"])
print health_statues
I was able to get the status of each of the 9 servers
[u'green', u'green', u'green', u'green', u'green', u'green', u'green', u'green', u'orange']
I was able to get the server status by hitting New Relic's API Based on this, I would like to apply it such as acquiring the server status at regular intervals and issuing an alert locally when a dangerous situation occurs.
Recommended Posts