Skip to content

Commit 281c0ca

Browse files
authored
Update example (#7)
1 parent 7cfc7cb commit 281c0ca

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

example.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,18 @@
88

99
async def main():
1010
"""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
1314
await data.get_data("system.cpu")
14-
1515
print(json.dumps(data.values, indent=4, sort_keys=True))
1616

1717
# Print the current value of the system's CPU
1818
print("CPU System:", round(data.values["system"], 2))
1919

20-
with aiohttp.ClientSession() as session:
21-
data = Netdata("localhost", loop, session, data="alarms")
20+
# Get the alarms which are present
2221
await data.get_alarms()
23-
2422
print(data.alarms)
2523

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-
3924
loop = asyncio.get_event_loop()
4025
loop.run_until_complete(main())

0 commit comments

Comments
 (0)