blob: 369a65fb916037cbfd4e970d669f98cc5789960b [file] [log] [blame]
koder aka kdanilovdda86d32015-03-16 11:20:04 +02001import yaml
2
3from api import start_monitoring, Empty
4from influx_exporter import connect, add_data
5
6monitor_config = yaml.load(open("config.yaml").read())
7
8uri = "udp://192.168.0.104:12001"
9infldb_url = "influxdb://perf:perf@192.168.152.42:8086/perf"
10conn = connect(infldb_url)
11
12sw_per_ip = {}
13count = 4
14expected = ['192.168.0.104', '192.168.152.41',
15 '192.168.152.39', '192.168.152.40']
16
17with start_monitoring(uri, monitor_config) as queue:
18 while True:
19 try:
20 (ip, port), data = queue.get(True, 1)
21
22 if 'sda1.sectors_written' in data:
23 val = data['sda1.sectors_written']
24 elif 'sdb.sectors_written' in data:
25 val = data['sdb.sectors_written']
26 else:
27 val = 0
28
29 sw_per_ip[ip] = sw_per_ip.get(ip, 0) + val
30 count -= 1
31
32 if 0 == count:
33 try:
34 vals = [sw_per_ip[ip] for ip in expected]
35 print ("{:>6}" * 4).format(*vals)
36 sw_per_ip = {}
37 count = 4
38 except KeyError:
39 pass
40
41 add_data(conn, ip, [data])
42 except Empty:
43 pass