- Nagios plugin to collect CPU metrics per core.
- Original author: Ashok Raja R ([email protected]).
- Dependencies: Linux 2.6.11+ (for cpu steal data), Python 2.3+ (for optparse).
- Copy the script to the Nagios plugin directory:
mv linux-cpu-usage.py /usr/lib/nagios/plugins/check_linux_cpu
- Add execute permissions to the script:
chmod +x /usr/lib/nagios/plugins/check_linux_cpu
- Edit /etc/nagios3/conf.d/commands.cfg:
define command {
command_name check_linux_cpu
command_line /usr/lib/nagios/plugins/check_linux_cpu -C $ARG1$ -w $ARG2$ -c $ARG3$
}
- Edit /etc/nagios3/conf.d/services.cfg:
define service {
hostgroup_name desired_hostgroup
service_description linux_cpu_usage
check_command check_linux_cpu!cpu!25!75
use generic-service
notification_options w,u,c,r
notifications_enabled 1
contact_groups emailonly
}
- Reload Nagios configuration:
/etc/init.d/nagios3 reload
This will set up an alert for all hosts in desired_hostgroup which warns at 25% overall CPU usage, and triggers a critical alert at 75% overall CPU usage.
check_cpu_percentage.py [options]
Options:
--version Show version number and exit
-h, --help Show this help message and exit
-C, --CPU Specify which CPU to check (cpu, cpu0, cpu1, ...)
-w, --warning Exit with WARNING status if CPU usage exceeds this percentage
-c, --critical Exit with CRITICAL status if CPU usage exceeds this percentage