7 def __init__(self, base_url="http://127.0.0.1:19999/api/v1
"):
8 """Create a new NetData interface.
10 :param base_url: Base URL of the NetData interface
16 res = requests.get(url)
18 if res.status_code != 200:
19 msg =
"NetData request not successful (url='{}', status_code={})".format(
22 raise requests.ConnectionError(msg)
27 """Reset the failed counter for given label in chart.
38 """Increase the failed counter for given label in chart.
40 Throws an exception if failed counter is greater or equal 5.
55 "Data from NetData was malformed {} times (chart='{}', label='{}')".format(
61 """Get NetData information."""
68 """Get data from NetData chart after a certain time.
70 :param chart: Chart identifier
71 :param after: Timedelta in seconds
73 url =
"{}/data?chart={}&format=json&after=-{}".format(
78 sdata = list(zip(*res[
"data"]))
81 for idx, label
in enumerate(res[
"labels"]):
82 np_array = numpy.array(sdata[idx])
83 if np_array.dtype == object
or (np_array ==
None).any():
84 msg =
"Data from NetData malformed: {}".format(label)
87 "... malformed data for Label <{}>: {}".format(label, np_array)
91 data[label] = np_array