aboutsummaryrefslogtreecommitdiffstats
path: root/show_dabmux_stats.py
blob: 6bb0673849c2a2250298e7cb2d9b628a221a72d1 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python2
#
# present statistics from dabmux Stats Server
# to munin

import sys
import json
import zmq
import os

ctx = zmq.Context()

def connect():
    """Create a connection to the dabmux stats server

    returns: the socket"""

    sock = zmq.Socket(ctx, zmq.REQ)
    sock.connect("tcp://localhost:12720")

    sock.send("info")
    version = json.loads(sock.recv())

    if not version['service'].startswith("ODR-DabMux"):
        sys.stderr.write("Wrong version\n")
        sys.exit(1)

    return sock

if len(sys.argv) == 1:
    sock = connect()
    sock.send("values")
    values = json.loads(sock.recv())['values']

    tmpl = "{ident:20}{maxfill:>8}{minfill:>8}{under:>8}{over:>8}{peakleft:>8}{peakright:>8}"
    print(tmpl.format(
        ident="id",
        maxfill="max",
        minfill="min",
        under="under",
        over="over",
        peakleft="peak L",
        peakright="peak R"))

    for ident in values:
        v = values[ident]['inputstat']
        print(tmpl.format(
            ident=ident,
            maxfill=v['max_fill'],
            minfill=v['min_fill'],
            under=v['num_underruns'],
            over=v['num_overruns'],
            peakleft=v['peak_left'],
            peakright=v['peak_right']))


elif len(sys.argv) == 2 and sys.argv[1] == "config":
    sock = connect()

    sock.send("config")

    config = json.loads(sock.recv())

    print(config['config'])