The monitoring agent comes with a set of plugins to monitor your servers: CPU, Memory, Disk, Network, and 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.
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.