Netdata/MongoDB/API: Difference between revisions
From charlesreid1
| Line 19: | Line 19: | ||
This displays a huge dictionary full of key-value pairs - all the quantities netdata is monitoring. | This displays a huge dictionary full of key-value pairs - all the quantities netdata is monitoring. | ||
At this point, the data can be inserted into the database, or it can be parsed to extract particular quantities of interest. Each key has a timestamp associated with it, in Unix epoch format (e.g., 1518321718). | |||
<pre> | |||
$ head -n30 output.json | |||
{ | |||
"ipv4.tcpofo": { | |||
"name": "ipv4.tcpofo", | |||
"context": "ipv4.tcpofo", | |||
"units": "packets/s", | |||
"last_updated": 1518321718, | |||
"dimensions": { | |||
"TCPOFOQueue": { | |||
"name": "inqueue", | |||
"value": 0.0 | |||
}, | |||
"TCPOFODrop": { | |||
"name": "dropped", | |||
"value": 0.0 | |||
}, | |||
"TCPOFOMerge": { | |||
"name": "merged", | |||
"value": 0.0 | |||
}, | |||
"OfoPruned": { | |||
"name": "pruned", | |||
"value": 0.0 | |||
} | |||
} | |||
}, | |||
"cgroup_happy_mongo.merged_ops": { | |||
"name": "cgroup_happy_mongo.merged_ops", | |||
"context": "cgroup.merged_ops", | |||
"units": "operations/s", | |||
"last_updated": 1518321718, | |||
</pre> | |||
Revision as of 04:36, 11 February 2018
The Netdata url schema exposes all metrics being measured by Netdata as a JSON-exportable REST url.
querying netdata API
To obtain the data that Netdata is reading, then, is a simple matter of making a URL request and translating the result into JSON. This is a breeze with the Python 3 requests library:
import requests, json
my_url = 'http://10.6.0.1:19999/api/v1/allmetrics?format=json&help=yes'
r = requests.get(url=my_url)
# dump resulting json
with open('output.json','w') as f:
json.dump( r.json(), f, indent=4 )
# print resulting json
print(r.json())
This displays a huge dictionary full of key-value pairs - all the quantities netdata is monitoring.
At this point, the data can be inserted into the database, or it can be parsed to extract particular quantities of interest. Each key has a timestamp associated with it, in Unix epoch format (e.g., 1518321718).
$ head -n30 output.json
{
"ipv4.tcpofo": {
"name": "ipv4.tcpofo",
"context": "ipv4.tcpofo",
"units": "packets/s",
"last_updated": 1518321718,
"dimensions": {
"TCPOFOQueue": {
"name": "inqueue",
"value": 0.0
},
"TCPOFODrop": {
"name": "dropped",
"value": 0.0
},
"TCPOFOMerge": {
"name": "merged",
"value": 0.0
},
"OfoPruned": {
"name": "pruned",
"value": 0.0
}
}
},
"cgroup_happy_mongo.merged_ops": {
"name": "cgroup_happy_mongo.merged_ops",
"context": "cgroup.merged_ops",
"units": "operations/s",
"last_updated": 1518321718,