Zabbix 自定义report
2024-10-19 08:48:30
#!/bin/bash
. /etc/profile
logdir='/home/admin/zabbix/zabbix_log'
mysql_host='localhost'
mysql_user='root'
mysql_passwd='*****'
mysql_database='zabbix'
year=`date +%Y`
month=`date +%m`
next_month=`echo $month+1|bc` #if today is the last day of month
#then run this script
##################################################
today=`date +%d`
last_day=`cal | xargs | awk '{print $NF}'`
if [ "$today" != "$last_day" ]; then
exit 1
fi
################################################# if [ ! -d $logdir ];then
mkdir $logdir
fi ##zabbix host month report
#select cpu avg unitil
mysql -h $mysql_host -u $mysql_user -p$mysql_passwd $mysql_database >$logdir/cpu$month.txt<<EOF
set names utf8;
select from_unixtime(hi.clock,'%m') as Date,g.name as Group_Name,h.host as Host, round(avg(hi.value_avg),1) as Cpu_Avg_Unitil,round(max(hi.value_max),1) as Cpu_Max_Unitil from hosts_groups hg join groups g on g.groupid = hg.groupid join items i on hg.hostid = i.hostid join hosts h on h.hostid=i.hostid join trends hi on i.itemid = hi.itemid where i.name='CPU unitil' and hi.clock >= UNIX_TIMESTAMP('${year}-${month}-01 00:00:00') and hi.clock < UNIX_TIMESTAMP('${year}-0${next_month}-01 00:00:00') group by h.host;
EOF
#select Mem usage
mysql -h $mysql_host -u $mysql_user -p$mysql_passwd $mysql_database >$logdir/mem$month.txt<<EOF
set names utf8;
select from_unixtime(hi.clock,'%m') as Date,g.name as Group_Name,h.host as Host, round(avg(hi.value_avg),1) as Mem_Avg_usage,round(max(hi.value_max),1) as Mem_Max_Usage from hosts_groups hg join groups g on g.groupid = hg.groupid join items i on hg.hostid = i.hostid join hosts h on h.hostid=i.hostid join trends hi on i.itemid = hi.itemid where i.name='Mem usage' and hi.clock >= UNIX_TIMESTAMP('${year}-${month}-01 00:00:00') and hi.clock < UNIX_TIMESTAMP('${year}-0${next_month}-01 00:00:00') group by h.host;
EOF sed -i '1d' $logdir/cpu$month.txt
sed -i '1d' $logdir/mem$month.txt
awk 'NR==FNR{a[$1,$2,$3,$4]=$0;next}{print a[$1,$2,$3,$4],"\t",$5,"\t",$6}' $logdir/cpu$month.txt $logdir/mem$month.txt >$logdir/result$month.txt
sed -i '1i Month\tGroup name\tHost\tCpu_avg_Unitil\tCpu_Max_Unitil\tMem_Avg_usage\tMem_Max_Usage' $logdir/result$month.txt rm -rf $logdir/cpu$month.txt
rm -rf $logdir/mem$month.txt
最新文章
- 安全测试 - 端口嗅探工具Nmap
- 路由器TL-WR941N V5.1:救砖、MOD
- CMPP错误码说明
- [Error] Error parsing XML: unbound prefix
- php两种include加载文件方式效率比较如下
- CoreText 使用教程
- tomcat下jndi的三种配置方式
- JavaScript高级程序设计(第三版)学习笔记1~5章
- kinect for windows - 环境搭建
- 【Electron】Electron开发入门(八):自定义electron框架外壳(shell)的菜单(Menu)
- Java第六周学习总结
- Jmeter(七)_if控制器+循环控制器+计数器控制接口分支
- 【Linux】-NO.160.Linux.1 -【升级Centos7】
- 20175202 《Java程序设计》迭代和JDB
- TopK
- 2016_NENU_CS_3
- Visual Studio 由于缺少调试目标
- IOP知识点(5)
- 网络之XML解析-GData
- 通过Fiddler肆意修改接口返回数据进行测试