M3 – Monitis Monitor Manager

A rabbit?

Writing custom monitors for Monitis is easy. On monitisexchange you can find many examples for custom monitors. However, now I bring you a surprise.

It is only rarely after I write a piece of code and represent it to others that I feel like pulling a rabbit out of a hat. On this occasion – there is something even better than a rabbit!

I’m proud to present you this time with ‘Monitis Monitor Manager‘, or M3 (M³) in short.


So what is M3?

M3 is perhaps the response for any of our Monitis custom monitors integration needs.

It’ll let you easily define agents, monitors and counters and easily load their data to Monitis.

Yes, it is easy to do it also manually, but here comes the rabbit out of the hat – M3 will help you parse output using regular expressions – simplifying the tasks in a few magnitudes – saving a lot of effort from your side.

Concrete examples should be examined and here they come, but please have a look at the sample XML file in the repository, as it might be self explanatory to most people.

Design and prerequisites

In order to operate M3, a basic level of Perl and Perl Regular Expressions is required.

In addition, in order to be as cross platform as possible, M3 also rely on the Perl-SDK of Monitis – checkout the module and install it (installation instructions are in the README over there)

M3 is actually a Perl package with a few functions, among them are:

  • add_agents()
  • invoke_agents()

You might just ask what is an agent?

Well, the hierarchy is as follows, an agent may have a few monitors, where a monitor may have a few counters (or metrics).

add_agents() will kindly add all of your agents and their corresponding monitors to Monitis, while invoke_agents() will update their data.

Example.pl holds a quick example which might just be self-explanatory.

M3 receives a configuration XML as an argument for its constructor and acts on it.

Adding agents is easy and not really interesting in terms of flow.

However, the invocation of agents (or monitors) is much more interesting. For each monitor we’ll set an executable to run in the <exectemplate> tag.

Then for each monitor we’ll configure a few counters under <metric> including their description and most importantly – the regular expression that’ll parse them.

M3 will run every monitor’s executable in turn and parse the regular expression for each counter, collecting the data and sending to Monitis.

Perhaps the most intricate task you’ll have to perform in this process is the definition of the regular expressions (might be subtle sometimes, I know) – but the task will get easier as M3 will provide you some verbose messages and also a dry run option.

Checkout and quick usage

As usual, it’s on github:

# mkdir -p /usr/share/monitisexchange && cd /usr/share/monitisexchange # git clone git://github.com/monitisexchange/Monitis-Linux-Scripts.git # cd Monitis-Linux-Scripts/M3 # cp Example.pl MyM3.pl # cp config_sample.xml config.xml

Edit your new configuration with your relevant API and secret key:

 # vim config.xml 

Easy invocation would now be with:

 # ./MyM3.pl config.xml 

Case study 1: iostat

We all know iostat. I’m going to show here how easy it is to integrate any of its counters into Monitis.

The output of iostat is fairly simple:

 # iostat -x sda Device: rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util sda    0.18     1.62    0.26    1.25    14.79    23.15    25.13     0.06   38.77  12.00   1.81

Yes, i chopped the irrelevant lines.

We’ll set in the configuration XML <exectemplate> to be ‘iostat -x sda’.

We’d like r/s (read per second) and w/s (write per second). M3 does almost everything for us, all that we’ll have to do is to write the proper regular expression. Have a look again at the sample XML file and you’ll see the simple regular expression of:


This would yield the r/s counter (you should have in parenthesis the value you’d like to extract).

Same goes for w/s, slightly different, but not too much.

Case study 2: top

Parsing regular expressions on top is just as easy, in the configuration sample we’ll parse free memory and used swap.

It works – try it!

Up at the top you can view the humble result of authentic data sampled from my computer (via iostat and top).

Icing on the cake

M3 will do another trick for you – templates!

In the example XML you might notice the use of %HOSTNAME%. M3 will kindly replace any instance of %SOMETHING% with the return value of the function MonitisMonitorManager::_get_SOMETHING(). Have a look at Example.pl – it’ll give you an idea about how to write these functions.

A nice option to debug your templates is to use the function MonitisMonitorManager::templated_xml() which would show you how the XML looks like after running your custom templates.

Perhaps M3 needs some built-in templates, however, right now I consider this functionality as icing on the cake rather than core functionality – but I’m open for any suggestions.

Actually we’re waiting for feedback on any aspect of M3 – bring it on!

Liked it? Sign up for Monitis and try it now! Don’t forget to check also monitisexchange – our git-hub open source repository for some more surprises.

Monitis Monitoring Platform

You might also like