标签:discovery 配置文件 项目信息 local joson
自定义discovery
1.通过脚本获取系统数据
2.把数据处理成joson格式的,自动监控的项目信息
3.获取自动监控的项目的数据
3.修改 agentd.conf的配置文件
UserParameter=process.discovery,/usr/local/zabbix/scripts/check_process.sh //自动检测的项目,即定义key值
UserParameter=process.resource[*],/usr/local/zabbix/scripts/process_monitor.sh $1 $2 //获取数据
4.测试
zabbix_get -s 192.168.36.130 -k process.discovery //必须为jison格式
zabbix_get -s 192.168.36.130 -k process.resource[tsg,mem]
5.在zabbix中配置自动发现
discovery---create discovery(key process.discovery)---item(key process.resource[{{#TABLENAME}},cpu])
check_process.sh 主要获取监控的项目名称
#!/bin/bash
pro_name=`ps -e -o ‘comm,pcpu,rsz‘ | awk ‘{print $1}‘ | sort -u | awk -F".exe" ‘{print $1}‘`
COUNT=`echo "$pro_name" |wc -l`
INDEX=0
echo {‘"data"‘:[
echo "$pro_name" | while read LINE;
do
echo -n ‘{"{#HOMEDNAME}":"‘$LINE‘"}‘
INDEX=`expr $INDEX + 1`
if [ $INDEX -lt $COUNT ]; then
echo ","
fi
done
echo ]}
process_monitor.sh 根据项目名称获取检测的数据
#!/bin/bash
process=$1
name=$2
case $2 in
mem)
echo "`ps -e -o ‘comm,pcpu,rsz‘ | awk ‘{a[$1]+=$3}END{for(key in a) print key,a[key]/1024}‘ | grep "$1\>" | awk ‘{print $2}‘`"
;;
cpu)
echo "`ps -e -o ‘comm,pcpu,rsz‘ | awk ‘{a[$1]+=$2}END{for(key in a) print key,a[key]}‘ | grep "$1\>" | awk ‘{print $2}‘`"
;;
*)
echo "Error input:"
;;
esac
exit 0
本文出自 “咚咚的博客” 博客,请务必保留此出处http://weadyweady.blog.51cto.com/3012956/1701048
标签:discovery 配置文件 项目信息 local joson
原文地址:http://weadyweady.blog.51cto.com/3012956/1701048