My first public Python Package “pyagentx”

I’ve just published my first public Python package “pyagentx”, the package will help you build “AgentX” agents to extend a master SNMP agent.

Let’s assume that you want to monitor your custom application from your Network Managment System (NMS), but the NMS only speak SNMP, this package allows you to extend the master SNMP agent to include your custom application metrics.

Project page on Github

Package page on Python Package Index

AgentX on Wikipedia

RFC 2741: Agent Extensibility (AgentX) Protocol

Monitoring Servers with Munin

This is a draft on configuring Munin to monitor services on a Linux machine, still dirty but published for my reference, if you have question let me know.

Monitoring Servers

sudo apt-get install munin

sudo htpasswd -c /etc/munin/htpasswd rayed

vi vi /etc/munin/munin-conf.d/example_com_site
:
[munin-node.example.com]
    address munin-node.example.com
    use_node_name yes
:


sudo vi vi /etc/nginx/sites-enabled/default
server {
:
location /munin/static/ {
        alias /etc/munin/static/;
        expires modified +1w;
}

location /munin/ {
        auth_basic            "Restricted";
        auth_basic_user_file  /etc/munin/htpasswd;

        alias /var/cache/munin/www/;
        expires modified +310s;
}
:
}

Monitored Servers

sudo apt-get install munin-node
sudo apt-get install munin-plugins-extra

sudo vi /etc/munin/munin-node.conf
:
allow ^172\.18\.100\.100$   # monitoring server address
:

Muni-node-configure

munin-node-configure is really useful command you can use it install all the plugins you need, when you run it will try to test if a plugin can be used or not (–suggest argument), and even give the commands needed to link the plugin automatically (–shell argument)

sudo munin-node-configure --suggest
sudo munin-node-configure --shell

MySQL plugin

sudo apt-get install libcache-perl libcache-cache-perl

sudo munin-node-configure --suggest --shell | sh

sudo munin-run mysql_commands 

sudo service munin-node restart

Memcached plugin

sudo aptitude install libcache-memcached-perl

sudo ln -s /usr/share/munin/plugins/memcached_ /etc/munin/plugins/memcached_bytes
sudo ln -s /usr/share/munin/plugins/memcached_ /etc/munin/plugins/memcached_counters
sudo ln -s /usr/share/munin/plugins/memcached_ /etc/munin/plugins/memcached_rates

sudo munin-run memcached_counters 

sudo service munin-node restart

Nginx Web Server

Configure Nginx to repoer its status under the URL http://localhost/nginx_status, which will be read from Munin Nginx plugin:

sudo vi /etc/nginx/sites-enabled/default
server {
:
        # STATUS
        location /nginx_status {
                stub_status on;
                access_log off;
                allow 127.0.0.1;
                allow ::1;
                allow my_ip;
                deny all;
        }
:
}

sudo service nginx restart

Configure Munin:

sudo apt-get install libwww-perl

sudo ln -s '/usr/share/munin/plugins/nginx_request' '/etc/munin/plugins/nginx_request'
sudo ln -s '/usr/share/munin/plugins/nginx_status' '/etc/munin/plugins/nginx_status'

sudo munin-run nginx_request

sudo service munin-node restart

Postgres

It is better to use munin-node-configure to configure and install postgres plugin, because it will detect installed databases and configure a graph for each.

sudo apt-get install libdbd-pg-perl
sudo munin-node-configure --suggest
sudo sh -c  'munin-node-configure --shell | grep postgres | sh '
sudo service munin-node restart

My New Project: AgentX Implementation in Python

Update: I changed the module name to ”pyagentx”, thank you Daniel for the suggestion.

During this Eid vacation I spent many hours working on AgentX implementation in Python.

You can find the project in GitHub:

https://github.com/rayed/pyagentx

What is AgentX?

AgentX is protocol to extend SNMP agents, defined in RFC 2741.

But what is SNMP? let’s say you have a Linux machine you want to monitor, you will use Simple Network Management Protocol or SNMP for short, you install an SNMP agent on the machine like Net-SNMP, and from your management station you connect to the SNMP agent and ask it for the data you want report on, for example the current state of network link.

What happen if you install new software, like PostgreSQL DB, and your SNMP agent doesn’t support it, how can you monitor it! The good news SNMP agents (e.g. Net-SNMP) can be extend with multiple options, the bad news most options are very hard.

One of the most flexible options is AgentX protocol, you will need to build an application that run AgentX protocol (AgentX SubAgent), upon startup it will contact the SNMP agent (AgentX master) and register a part of the MIB tree that your app will handle, the SNMP agent (AgentX master) will forward all queries to your app which will return the result back to the master which will forward it to the management station (Cacti, NMS).

Net-SNMP already have an API to build AgentX Sub Agent, and there are Python module that utilise it, but unfortunately it doesn’t look active, and as far as I know Net-SNMP API it self isn’t the easiest thing to work with.

This is why I started working with Pure Python implementation for AgentX protocol, it is already in a working condition and tested with Net-SNMP agent, I’ve some more issues to resolve before I can use it in production.

So please if you are interested in the field give my module a try, and let me know how can improve it, and also suggest better name.