aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-05-11 18:16:19 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-05-11 18:16:19 +0200
commit6525e843832e058cb3097fc4fbe0166071bb4136 (patch)
tree599ad459e2cf5c25a36378e4e418ca7a47c2c807
parent7513cf3dde274e945420e3e56fe4c66985f9f225 (diff)
downloadmmbtools-monit-6525e843832e058cb3097fc4fbe0166071bb4136.tar.gz
mmbtools-monit-6525e843832e058cb3097fc4fbe0166071bb4136.tar.bz2
mmbtools-monit-6525e843832e058cb3097fc4fbe0166071bb4136.zip
First version of monit tool
-rw-r--r--.gitignore1
-rw-r--r--README.md16
-rwxr-xr-xmonit.py46
-rw-r--r--static/green.png (renamed from images/green.png)bin82817 -> 82817 bytes
-rw-r--r--static/noaudio.pngbin0 -> 3856 bytes
-rw-r--r--static/orange.png (renamed from images/orange.png)bin82307 -> 82307 bytes
-rw-r--r--static/red.png (renamed from images/red.png)bin89601 -> 89601 bytes
-rw-r--r--static/traffic-lights-led.xcf (renamed from images/traffic-lights-led.xcf)bin589551 -> 589551 bytes
-rw-r--r--templates/index.html33
9 files changed, 96 insertions, 0 deletions
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/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/images/green.png b/static/green.png
index 12b28eb..12b28eb 100644
--- a/images/green.png
+++ b/static/green.png
Binary files differ
diff --git a/static/noaudio.png b/static/noaudio.png
new file mode 100644
index 0000000..56fff4a
--- /dev/null
+++ b/static/noaudio.png
Binary files differ
diff --git a/images/orange.png b/static/orange.png
index 0ad373f..0ad373f 100644
--- a/images/orange.png
+++ b/static/orange.png
Binary files differ
diff --git a/images/red.png b/static/red.png
index ee284c4..ee284c4 100644
--- a/images/red.png
+++ b/static/red.png
Binary files differ
diff --git a/images/traffic-lights-led.xcf b/static/traffic-lights-led.xcf
index 12bddc4..12bddc4 100644
--- a/images/traffic-lights-led.xcf
+++ b/static/traffic-lights-led.xcf
Binary files 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 @@
+<!doctype html>
+<html>
+<head>
+ <title>ODR-DabMux Monitoring</title>
+ <meta http-equiv="refresh" content="15">
+</head>
+<body>
+<h1>Statistics for ODR-DabMux running on '{{ name }}'</h1>
+<table>
+ <thead><td>Input Name</td><td>State</td></thead>
+ {% for inp in inputs %}
+ <tr><td><b>{{ inp.name }}:</b></td><td>
+ {% if inp.state == "NoData" %}
+ <img src="static/red.png" width="29" height="64" alt="No Date" />
+ No Data
+ {% elif inp.state == "Unstable" %}
+ <img src="static/orange.png" width="29" height="64" alt="Unstable" />
+ Unstable
+ {% elif inp.state == "Silent" %}
+ <img src="static/orange.png" width="29" height="64" alt="Unstable" />
+ <img src="static/noaudio.png" width="60" height="30" alt="No audio" />
+ {% elif inp.state == "Streaming" %}
+ <img src="static/green.png" width="29" height="64" alt="Unstable" />
+ {% else %}
+ Unknown state {{ inp.state }} !
+ {% endif %}
+ </td></tr>
+ {% endfor %}
+</table>
+<p>generated on {{ date }}</p>
+</body>
+</html>
+