Custom Monitors

How to monitor your application with your custom script.

We try to provide necessary monitors to our customers. But if needed, you can create your own custom monitors using python.

To use your custom monitor with ecmanaged agent, you need to put it in under a folder inside custom monitoring plugin folder, which in linux is '/opt/ecmanaged/ecagent/monitor/custom/'. The folder name should corresponds to the timeout period of your script. So, if you want to run your custom monitor with a timeout of 10 seconds, you should put your monitoring script inside '/opt/ecmanaged/ecagent/monitor/custom/10/' folder. You can put multiple custom monitors under same folder if they have same timeout.

You need to be sure that all the libraries and dependencies are installed in the target server so that your monitor can run without any error. The best way to check it to run it manually once in the specified folder.

Python Custom Monitors With Graphs

You need to import and subclass MPlugin to write your custom monitor. The basic structure of your code will be like this:

#!/usr/bin/env python

import sys

from __mplugin import MPlugin
from __mplugin import OK, CRITICAL, TIMEOUT

class CustomMonitor(MPlugin):

    def get_stats(self):
        # Gather your monitoring data, It should be a dictionary,
        # in { 'metric1: value1, 'metric2': value2, 'metric3': value3  } format. 
        # Values should be integer or floating point numbers.
        return data

    def run(self):
        data = self.get_stats()

        # You can return critical or error status
        if not data:
           self.exit(CRITICAL, message="Stat data is empty")

        # Your data can be a counter(which increments over time) or 
        # a gauge(which is a exact information). 
        # The code below shows how to process them.

        counter_data = [

        gauge_data = [

        tmp_counter = {}

        for idx in counter_data:
                tmp_counter[idx] = int(data.get(idx,0))
                tmp_counter[idx] = data.get(idx,0)

        # Process your counter data to get values_now - values_previous 
        # You need to change the second parameter to the counters function for 
        # each monitor, which is in this case 'custom_monitor'  

        tmp_counter = self.counters(tmp_counter,'custom_monitor')

        tmp_gauge = {}

        # This to make sure that you have a entry for your gauge data. 

        for idx in gauge_data:
                tmp_gauge[idx] = int(data.get(idx,0))
                tmp_gauge[idx] = data.get(idx,0)

        # Overwite the data dictionary

        data = tmp_counter.copy()

        # You need to provide a metrics dictionary which is used to create the graphs in ecmanaged web         
        metrics = {
            'Graph1': {
                'label1': data['metric1'],
                'label2': data['metric2']
            'Graph2': {
                'label1': data['metric3']
        # You have to return status OK, data and metrics

monitor = CustomMonitor()

Custom Monitor Without Graphs

You can create custom monitor using your preffered scripting language. These monitors will not support graphs. You can only return status. The supported statuses are given below:

Monitor Return Code Service State
0 OK