-
Notifications
You must be signed in to change notification settings - Fork 0
/
showheartbeat.py
41 lines (34 loc) · 1.22 KB
/
showheartbeat.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
import curses
from widgets import Table, rectangle
class heartbeatwin:
def __init__(self, xpos, ypos, width, height):
self.win = curses.newwin(height,width, ypos, xpos)
self.height = height
self.width = width
self.xpos = xpos
self.ypos = ypos
self.table = Table(
self.win,
1,
2,
self.width-3,
self.height-3,
[
{
"width": self.width-3,
"padding_left": 1,
"text": lambda col, row, item, data: item[0],
"attributes": lambda col, row, item, data: curses.color_pair(2) if item[1] else curses.color_pair(1)
}
])
self.win.addstr(0, 0, 'Infrastructure:')
rectangle(self.win,0,1,self.width,self.height-1)
self.heartbeats = {}
def update(self, topic, payload):
if len(payload) == 0:
self.heartbeats.pop(topic[len('heartbeat/'):])
else:
self.heartbeats[topic[len('heartbeat/'):]] = payload[0]
self.table.apply_data( list(sorted(self.heartbeats.items())) )
def show(self):
self.win.refresh()