All HowTo's Linux Redhat, Fedora and CentOS Linux Web Servers

Create your own Munin Plugin on Redhat/CentOS

This article explains how to create your own munin plugin. We will monitor the number of Apache and/or Nginx processors running.

On the munin-node (client), create a file as “/usr/share/munin/plugins/webserver-count” and put the following content into it:

#!/bin/sh
 
case $1 in
config)
cat <<'EOM'
graph_title Webserver Count
graph_vlabel load
load.label load
load.warning 100
load.critical 120
EOM
exit 0;;
esac
 
printf "load.value "
ps aux | egrep 'nginx|httpd|apache' | nl | wc -l

Set it’s permissions:

chmod 755 /usr/share/munin/plugins/webserver-count
chown root.root /usr/share/munin/plugins/webserver-count

If SELinux is running, make sure to change the label as follows:

restorecon -Rv /usr/share/munin/plugins/

Start it by restarting munin-node:

service munin-node restart
chkconfig munin-node on

Now test it by telnet’ing to it form the localhost and do the following:

]# telnet localhost 4949
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
# munin node at server1
list
webserver-count cpu df df_inode entropy forks fw_conntrack fw_forwarded_local fw_packets if_err_eth0 if_eth0 interrupts irqstats load memory netstat open_files open_inodes postfix_mailqueue postfix_mailvolume proc_pri processes selinux_avcstat swap threads uptime users vmstat
fetch webserver-count
load.value 14

As you can see, there are 14 webserver processors running on this server. We will get alerts if the number of processors reaches 100. We get more alerts if it reaches 120. Adjust those values to fit and then restart the munin-node services.