Introduction:

The monitoring agent includes a range of plugins designed to monitor various aspects of your servers, including CPU, Memory, Disk, Network, and Processes. Additionally, it provides plugins for monitoring services such as MongoDB, PHP-FPM, NGiNX, and Apache2/httpd.

In addition to these pre-built plugins, you have the option to monitor other metrics on your server by developing your own plugin. These custom plugins are written in either Python 2 or Python 3. To determine the Python version your agent is running, navigate to the plugin directory and run "agent360 info" to unveil the Python version in use.

 Time depends on your coding experience

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.

These 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 in the plugin tab for your server, or on the overview page.

If you need any help creating your custom plugin, you can contact the vendor directly at  [email protected].

Require additional assistance?

Our dedicated Australian support team is ready to help. Reach out to us via email at [email protected] or by submitting a support ticket through your Zeniar Portal.

Was this answer helpful? 579 Users Found This Useful (598 Votes)