|
8 | 8 |
|
9 | 9 | async def main(): |
10 | 10 | """Get the data from a Netdata instance.""" |
11 | | - with aiohttp.ClientSession() as session: |
12 | | - data = Netdata("localhost", loop, session, data="data") |
| 11 | + async with aiohttp.ClientSession() as session: |
| 12 | + data = Netdata("localhost", loop, session) |
| 13 | + # Get data for the CPU |
13 | 14 | await data.get_data("system.cpu") |
14 | | - |
15 | 15 | print(json.dumps(data.values, indent=4, sort_keys=True)) |
16 | 16 |
|
17 | 17 | # Print the current value of the system's CPU |
18 | 18 | print("CPU System:", round(data.values["system"], 2)) |
19 | 19 |
|
20 | | - with aiohttp.ClientSession() as session: |
21 | | - data = Netdata("localhost", loop, session, data="alarms") |
| 20 | + # Get the alarms which are present |
22 | 21 | await data.get_alarms() |
23 | | - |
24 | 22 | print(data.alarms) |
25 | 23 |
|
26 | | - with aiohttp.ClientSession() as session: |
27 | | - data = Netdata("localhost", loop, session) |
28 | | - await data.get_allmetrics() |
29 | | - |
30 | | - print(data.metrics) |
31 | | - |
32 | | - # Print the current value for the system's CPU |
33 | | - print( |
34 | | - "CPU System:", |
35 | | - round(data.metrics["system.cpu"]["dimensions"]["system"]["value"], 2), |
36 | | - ) |
37 | | - |
38 | | - |
39 | 24 | loop = asyncio.get_event_loop() |
40 | 25 | loop.run_until_complete(main()) |
0 commit comments