Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [How to get per-core CPU monitoring through zabbix-aggent:
- 1.1. Copy this script to host
- #!/bin/bash
- # This script detects number of cores available in Linux system
- CORES=$(mpstat -P ALL | sed 1,4d | awk '{ print $3}')
- echo "{"
- echo -e "\t\"data\":["
- for core in ${CORES}; do
- echo -e "\t\t{"
- #echo -e "\t\t\t\"{#CORENAME}\":\"Core$core\","
- echo -e "\t\t\t\"{#COREINDEX}\":\"$core\"},"
- done | sed '$ s/,/]}/'
- ####################
- 1.2. Copy this script to host, e.g. /etc/scripts/zabbix/cpu_perCoreStat.sh
- #!/bin/bash
- # This script gets CPU Utilization per core.
- getStat() {
- # $1 - type of value - user, system, idle, iowait
- # $2 - core number, 0 is for all cores stat
- CORE="$2"
- case "${1}" in
- sys)
- if [ "$CORE" = "0" ];then
- mpstat -P ALL | grep all | awk '{ print $6 }'
- else
- mpstat -P $CORE | sed 1,3d | awk '{ print $6 }'
- fi
- ;;
- user)
- if [ "$CORE" = "0" ];then
- mpstat -P ALL | grep all | awk '{ print $4 }'
- else
- mpstat -P $CORE | sed 1,3d | awk '{ print $4 }'
- fi
- ;;
- idle)
- if [ "$CORE" = "0" ];then
- mpstat -P ALL | grep all | awk '{ print $12 }'
- else
- mpstat -P $CORE | sed 1,3d | awk '{ print $12 }'
- fi
- ;;
- iowait)
- if [ "$CORE" = "0" ];then
- mpstat -P ALL | grep all | awk '{ print $7 }'
- else
- mpstat -P $CORE | sed 1,3d | awk '{ print $7 }'
- fi
- ;;
- esac
- }
- while getopts ":u:s:i:w:" opt;do
- # $OPTARG - argument given after parameter, e.g. if we type $(script -s 25), $OPTARG will be "25"
- case $opt in
- s)
- getStat sys $OPTARG
- ;;
- u)
- getStat user $OPTARG
- ;;
- i)
- getStat idle $OPTARG
- ;;
- w)
- getStat iowait $OPTARG
- ;;
- \?)
- echo "Invalid argument : -$OPTARG"
- ;;
- esac
- shift
- done
- #####################################
- 1.3. zabbix_agentd.conf:
- UserParameter=cpu.cores.discovery,sudo /etc/scripts/zabbix/cpu.cores.discovery
- UserParameter=system.cpu.idle[*],sudo /etc/scripts/zabbix/cpu_perCoreStat -i $1
- UserParameter=system.cpu.iowait[*],sudo /etc/scripts/zabbix/cpu_perCoreStat -w $1
- UserParameter=system.cpu.sys[*],sudo /etc/scripts/zabbix/cpu_perCoreStat -s $1
- UserParameter=system.cpu.user[*],sudo /etc/scripts/zabbix/cpu_perCoreStat -u $1
- 1.4. Modify sudo parameters in /etc/sudoers:
- zabbix ALL=(ALL) NOPASSWD: /etc/scripts/zabbix/
- Defaults:zabbix !requiretty
- 1.5. Don't forget to chmod +x all of your scripts :)
- 2.1 Import template, and add them to host
Advertisement
Add Comment
Please, Sign In to add comment