Extend snmpd to add detailed CPU statistics, per CPU (again)

For easier use with Cacti, it is easier to group statistics per type instead of per CPU. So you would have a parent OID for CPU time spent by user with many values (one per CPU).

Put the following in /etc/snmp/percpudetail:

#!/bin/bash
case "$1" in
  "user")
    grep ^cpu /proc/stat | awk '{print 2}' ;;
  "nice")
    grep ^cpu /proc/stat | awk '{print 3}' ;;
  "system")
    grep ^cpu /proc/stat | awk '{print 4}' ;;
  "idle")
    grep ^cpu /proc/stat | awk '{print 5}' ;;
  "iowait")
    grep ^cpu /proc/stat | awk '{print 6}' ;;
  "irq")
    grep ^cpu /proc/stat | awk '{print 7}' ;;
  "softirq")
    grep ^cpu /proc/stat | awk '{print 8}' ;;
esac

Make it executable:

chmod +x /etc/snmp/percpudetail

Then in your /etc/snmp/snmpd.conf file, put the following lines:

extend cpuuser /etc/snmp/percpudetail user
extend cpunice /etc/snmp/percpudetail nice
extend cpusystem /etc/snmp/percpudetail system
extend cpuidle /etc/snmp/percpudetail idle
extend cpuiowait /etc/snmp/percpudetail iowait
extend cpuirq /etc/snmp/percpudetail irq
extend cpusoftirq /etc/snmp/percpudetail softirq

Restart snmpd and you can poll those new OIDs.

This entry was posted in Computer, Linux, Networking. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *