-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharts.py
executable file
·41 lines (35 loc) · 982 Bytes
/
charts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
class LineChart(object):
@staticmethod
def get_coordinates(metrics):
x = []
y = []
for metric in metrics:
x.append(metric.time)
y.append(float(metric.value))
return (x, y)
@staticmethod
def render(host_name, metric_name, metrics):
x, y = LineChart.get_coordinates(metrics)
return {
"data": [{
"type": "scatter",
"mode": "lines",
"x": x,
"y": y,
"name": metric_name,
"line": {
"color": "blue"
}
}],
"layout": [{
"title": f"{host_name} - {metric_name}",
"xaxis": {
"type": "time",
"title": "time"
},
"yaxis": {
"title": metric_name
}
}]
}