From 6525e843832e058cb3097fc4fbe0166071bb4136 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 11 May 2014 18:16:19 +0200 Subject: First version of monit tool --- .gitignore | 1 + README.md | 16 +++++++++++++++ images/green.png | Bin 82817 -> 0 bytes images/orange.png | Bin 82307 -> 0 bytes images/red.png | Bin 89601 -> 0 bytes images/traffic-lights-led.xcf | Bin 589551 -> 0 bytes monit.py | 46 ++++++++++++++++++++++++++++++++++++++++++ static/green.png | Bin 0 -> 82817 bytes static/noaudio.png | Bin 0 -> 3856 bytes static/orange.png | Bin 0 -> 82307 bytes static/red.png | Bin 0 -> 89601 bytes static/traffic-lights-led.xcf | Bin 0 -> 589551 bytes templates/index.html | 33 ++++++++++++++++++++++++++++++ 13 files changed, 96 insertions(+) create mode 100644 .gitignore create mode 100644 README.md delete mode 100644 images/green.png delete mode 100644 images/orange.png delete mode 100644 images/red.png delete mode 100644 images/traffic-lights-led.xcf create mode 100755 monit.py create mode 100644 static/green.png create mode 100644 static/noaudio.png create mode 100644 static/orange.png create mode 100644 static/red.png create mode 100644 static/traffic-lights-led.xcf create mode 100644 templates/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv diff --git a/README.md b/README.md new file mode 100644 index 0000000..f826400 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +Simple Monitoring for the ODR-mmbTools +====================================== + +How to get started +------------------ + +This little webpage uses python and (Flask)[http://flask.pocoo.org]. + +To get started, install (virtualenv)[http://www.virtualenv.org] +(maybe try *apt-get install python-virtualenv*) and then do + + virtualenv venv + source venv/bin/activate + pip install Flask + + diff --git a/images/green.png b/images/green.png deleted file mode 100644 index 12b28eb..0000000 Binary files a/images/green.png and /dev/null differ diff --git a/images/orange.png b/images/orange.png deleted file mode 100644 index 0ad373f..0000000 Binary files a/images/orange.png and /dev/null differ diff --git a/images/red.png b/images/red.png deleted file mode 100644 index ee284c4..0000000 Binary files a/images/red.png and /dev/null differ diff --git a/images/traffic-lights-led.xcf b/images/traffic-lights-led.xcf deleted file mode 100644 index 12bddc4..0000000 Binary files a/images/traffic-lights-led.xcf and /dev/null differ diff --git a/monit.py b/monit.py new file mode 100755 index 0000000..dd8adbe --- /dev/null +++ b/monit.py @@ -0,0 +1,46 @@ +#!python +import json +import socket +from datetime import datetime +from flask import Flask +from flask import render_template +app = Flask(__name__) + +SOCK_RECV_SIZE = 10240 + +def get_state(): + """Create a connection to the dabmux stats server + and ask for the state + + returns: state""" + + sock = socket.socket() + sock.connect(("localhost", 12720)) + + version = json.loads(sock.recv(SOCK_RECV_SIZE)) + + if not version['service'].startswith("ODR-DabMux"): + return "Wrong version: '{}'\n".format(version['service']) + + sock.send("state\n") + state_data = json.loads(sock.recv(SOCK_RECV_SIZE)) + sock.close() + + return state_data + +@app.route('/') +def index_state(): + state_json = get_state() + + inputs = [{'name':name, 'state':state_json[name]['state']} for name in state_json] + + now = str(datetime.now()) + + return render_template("index.html", + inputs=inputs, + name="test mux", + date=now) + +if __name__ == '__main__': + app.run(debug=True) + diff --git a/static/green.png b/static/green.png new file mode 100644 index 0000000..12b28eb Binary files /dev/null and b/static/green.png differ diff --git a/static/noaudio.png b/static/noaudio.png new file mode 100644 index 0000000..56fff4a Binary files /dev/null and b/static/noaudio.png differ diff --git a/static/orange.png b/static/orange.png new file mode 100644 index 0000000..0ad373f Binary files /dev/null and b/static/orange.png differ diff --git a/static/red.png b/static/red.png new file mode 100644 index 0000000..ee284c4 Binary files /dev/null and b/static/red.png differ diff --git a/static/traffic-lights-led.xcf b/static/traffic-lights-led.xcf new file mode 100644 index 0000000..12bddc4 Binary files /dev/null and b/static/traffic-lights-led.xcf differ diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..78a4696 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,33 @@ + + + + ODR-DabMux Monitoring + + + +

Statistics for ODR-DabMux running on '{{ name }}'

+ + + {% for inp in inputs %} + + {% endfor %} +
Input NameState
{{ inp.name }}: + {% if inp.state == "NoData" %} + No Date + No Data + {% elif inp.state == "Unstable" %} + Unstable + Unstable + {% elif inp.state == "Silent" %} + Unstable + No audio + {% elif inp.state == "Streaming" %} + Unstable + {% else %} + Unknown state {{ inp.state }} ! + {% endif %} +
+

generated on {{ date }}

+ + + -- cgit v1.2.3