Skip to content

Commit a5075e2

Browse files
committed
Update example
1 parent f6fa216 commit a5075e2

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

example.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
"""Sample code to interact with a Netdata instance."""
22
import asyncio
3-
import aiohttp
43
import json
54

65
from netdata import Netdata
76

87

98
async def main():
109
"""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+
2331

2432
loop = asyncio.get_event_loop()
2533
loop.run_until_complete(main())

0 commit comments

Comments
 (0)