|
1 | 1 | """Sample code to interact with a Netdata instance.""" |
2 | 2 | import asyncio |
3 | | -import aiohttp |
4 | 3 | import json |
5 | 4 |
|
6 | 5 | from netdata import Netdata |
7 | 6 |
|
8 | 7 |
|
9 | 8 | async def main(): |
10 | 9 | """Get the data from a Netdata instance.""" |
11 | | - async with aiohttp.ClientSession() as session: |
12 | | - data = Netdata("localhost", loop, session) |
13 | | - # Get data for the CPU |
14 | | - await data.get_data("system.cpu") |
15 | | - print(json.dumps(data.values, indent=4, sort_keys=True)) |
16 | | - |
17 | | - # Print the current value of the system's CPU |
18 | | - print("CPU System:", round(data.values["system"], 2)) |
19 | | - |
20 | | - # Get the alarms which are present |
21 | | - await data.get_alarms() |
22 | | - print(data.alarms) |
| 10 | + client = Netdata("localhost") |
| 11 | + |
| 12 | + # Get all metrics |
| 13 | + await client.get_info() |
| 14 | + print(client.info) |
| 15 | + |
| 16 | + # Get details of a available chart |
| 17 | + await client.get_chart("system.cpu") |
| 18 | + print(json.dumps(client.values, indent=4, sort_keys=True)) |
| 19 | + |
| 20 | + # Print the current value of the system's CPU |
| 21 | + print("CPU System:", round(client.values["system"], 2)) |
| 22 | + |
| 23 | + # Get the alarms which are present |
| 24 | + await client.get_alarms() |
| 25 | + print(client.alarms) |
| 26 | + |
| 27 | + # Get all metrics |
| 28 | + await client.get_allmetrics() |
| 29 | + print(client.metrics) |
| 30 | + |
23 | 31 |
|
24 | 32 | loop = asyncio.get_event_loop() |
25 | 33 | loop.run_until_complete(main()) |
0 commit comments