Custom Plugins

Last modified: October 12, 2021


Overview

The monitoring agent comes with a set of plugins to monitor your servers: CPU, Memory, Disk, Network, Processes. It also comes with a set of plugins for your services such as MongoDB, PHP-FPM, NGiNX, Apache2/httpd.

Besides these plugins, it’s possible to monitor other metrics on your server by building your own plugin. Plugins are written in Python 2 or Python 3. To find out the version of python your agent is running, run agent360 info in the plugin directory to reveal the python version.

Base

The base of a plugin is as follows:

#!/usr/bin/env
python import plugins

class Plugin(plugins.BasePlugin):
__name__ = 'fridge'

def run(self, *unused):
results = {'milk': 10, 'eggs': 4}
return results
if __name__ == '__main__':
Plugin().execute()

This is a simple example plugin. You have to save the plugin to the plugins directory. You can find out your plugin directory by running the agent360 info command:

Version: 1.1.18
Plugins enabled: memory, diskusage, process, loadavg, network, cpu, ping, iostat, swap, system
Plugins directory: /usr/local/lib/python2.7/dist-packages/agent360/plugins
Server: 53bad1a222c9eea0378a4567

Save the plugin title under the same value as the __name__. For example, in this case we would save the plugin to /usr/local/lib/python2.7/dist-packages/agent360/plugins/fridge.py

Now we can test the plugin by running the following command: sudo -u agent360 agent360 test fridge

It will return results similar to the following:

fridge:
{"eggs": 4,"milk": 10}

If this doesn’t work, try to run this plugin as root to check if there is a permission issue.

fridge:
{"eggs": 4,"milk": 10}

If the test is successful, you can enable the plugin by editing the configuration file, usually located at /etc/agent360.ini. Add a new section to this file called [fridge] (same as the name value in your plugin file).

[fridge]
enabled = yes

Using configuration values

You might need to use configuration values in your plugin, for example an address to connect to.

This values can be stored in the /etc/agent360.ini configuration file. In the last example, we could add an address:

[fridge]
enabled = yes
location = http://192.168.0.100/fridge.json

We can now retrieve the configuration values in the plugin.

#!/usr/bin/env python
import plugins
import json
import urllib2

class Plugin(plugins.BasePlugin):
__name__ = 'fridge'

def run(self, config):
request = urllib2.Request(config.get(__name__, 'location'))
raw_response = urllib2.urlopen(request)
fridge_data = json.loads(raw_response.read(), object_hook=ascii_encode_dict)
results = {'milk': fridge_data['milk'], 'eggs': fridge_data['eggs']}
return results

if __name__ == '__main__':
Plugin().execute()

The run() function now has a second parameter with the config object. We’re also importing urllib2 and JSON to retrieve data.

To start sending data to 360 Monitoring, restart the agent with the service agent360 restart command.

After setting up your custom plugin, you can find the data at the plugin tab for your server, or on the overview page.

If you need any help creating your custom plugin, feel free to contact us through the live chat or by e-mail at vincent@monitoring.platform360.io

We accept pull requests to our GitHub repo, plugins will be added to our releases when we accept them!


Get Started With 360

360 Dashboard

360 Monitoring Dashboard