Monitoring With Munin

From MythTV Official Wiki
Jump to: navigation, search

Important.png Note: This page is work in progress

Munin is a frontend for the popular RRDTool, Munin can produce graphing based on the output of simple shell scripts. The following script can be used with Munin to create a graph of tuner statuses.

Tuner usage statisics

Munin - MythTV Tuner Usage.png

The state values in the script come from I think you should only ever see -1, 0, 1, and 7 as Encoder states. These values may change in future versions.

PythonIcon.png mythtv-tuners

#!/usr/bin/env python
""" Place this script in /etc/munin/plugins/
    then restart the munin-node service.

    Copyright 2012 Tom Hayward <>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <>.
import httplib
from lxml import etree
import sys

if "config" in sys.argv:
  print """graph_title MythTV Tuners
graph_vlabel Number of Tuners
graph_args --base 1000 -l 0
graph_category mythtv
recording.label Recording
recording.type GAUGE
recording.draw AREASTACK
recording.min 0
available.label Available
available.type GAUGE
available.draw AREASTACK
available.min 0
available.warning 0:
live.label Live TV
live.type GAUGE
live.draw AREASTACK
live.min 0
error.label Error
error.type GAUGE
error.draw AREASTACK
error.min 0
error.critical 0:0"""

conn = httplib.HTTPConnection("localhost:6544")
conn.request("GET", "/Status/GetStatus")
r1 = conn.getresponse()
results =

recording = 0
available = 0
live = 0
error = 0

root = etree.fromstring(results)
for encoder in root.find("Encoders").findall("Encoder"):
  state = int(encoder.attrib['state'])
  if state == -1:
    error += 1
  elif state == 0:
    available += 1
  elif state == 1:
    live += 1
  elif state == 7:
    recording += 1
    error += 1

print "recording.value", recording
print "available.value", available
print "live.value", live
print "error.value", error