koder aka kdanilov | dda86d3 | 2015-03-16 11:20:04 +0200 | [diff] [blame] | 1 | import yaml |
| 2 | |
| 3 | from api import start_monitoring, Empty |
| 4 | from influx_exporter import connect, add_data |
| 5 | |
| 6 | monitor_config = yaml.load(open("config.yaml").read()) |
| 7 | |
| 8 | uri = "udp://192.168.0.104:12001" |
| 9 | infldb_url = "influxdb://perf:perf@192.168.152.42:8086/perf" |
| 10 | conn = connect(infldb_url) |
| 11 | |
| 12 | sw_per_ip = {} |
| 13 | count = 4 |
| 14 | expected = ['192.168.0.104', '192.168.152.41', |
| 15 | '192.168.152.39', '192.168.152.40'] |
| 16 | |
| 17 | with 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 |