Custom Monitors in Monitis with Python

Custom Monitors in Monitis with PythonAs a system administrator, you will often find yourself responsible for managing a wide range of operating systems.  Since many management tools are only available for a subset of the platforms, this means you may be forced to work with more management tools than you’d like.

Cross-platform tools, when you can find them, greatly simplify the job of keeping track of so many disparate systems. Monitis provides agents for Windows and Linux systems, with a number of built-in metrics.  But, in situations where those metrics aren’t enough, or when you need to support systems that don’t have an agent available, using custom monitors written in a cross-platform scripting language can provide consistency across all of your managed systems.  Python can provide just such a scripting language.  In this article, we’ll walk through an example of using Python to measure system load.

Getting started

First off, ensure that you have Python installed, and that the optional elementtree module is installed.  Installing those is beyond the scope of this article, but plenty of documentation is available at
As an example, let’s look at measuring system load and reporting the results to a monitor in Monitis.  In Python, the system load averages can be retrieved with os.getloadavg() on UNIX systems. With systems monitoring, the code to make measurements will often vary by platform.  The advantage with Python is that outside of the measurement code, everything else can remain consistent.

>>> import os >>> os.getloadavg()
(0.23828125, 0.20263671875, 0.20166015625)

To use this in a script to post the result to Monitis, just create a connection to the Monitis server, get the load averages, and send the results.  If it sounds easy, that’s because it is.

# Monitis server will be used for all requests
monitis = MonitisServer(apiKey, apiSecret)
# Do the load averages check, and the add the result to monitis
loadAverages = os.getloadavg()
loadAveragesResult = \
print monitis.addResult(monitorTag='loadMonitor',

Let’s try this out with some example code.  First, clone the GitHub repository Python-Monitis-Scripts at, and then we’ll run the scripts.

# create a new monitor
$ ./ -a  -s  \
 -r "1m:1 Min. Average:processes:4;5m:5 Min. Average:processes:4;15m:15 Min. Average:processes:4"\
 -m loadMonitor  -n "load monitor"

# list existing monitors
$ ./ -a  -s   -l
491	loadMonitor	load monitor
794	loginMonitor	login monitor

# delete a monitor
$ ./ -a  -s  -d -i 794

$ ./ -a  -s   -l
491	loadMonitor	load monitor

# record a metric to an existing monitor
$ python ./ -a  -s


And now, we can see the result at

Now that you’ve seen how to add custom monitors, and to get the data into Monitis, it’s time to try it out yourself.  Download the code from the GitHub repository at
$ git clone

Cloning into Python-Monitis-Scripts... remote: Counting objects: 12, done. remote: Compressing objects: 100% (9/9), done. remote: Total 12 (delta 5), reused 10 (delta 3) Unpacking objects: 100% (12/12), done. 

Now that you’ve got the code checked out, run the examples shown above to see how it all works for yourself.  That’s it for now. Find full source code here,

Custom Monitors in Monitis with Python

You might also like