#!/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

  

最新文章

  1. 安全测试 - 端口嗅探工具Nmap
  2. 路由器TL-WR941N V5.1:救砖、MOD
  3. CMPP错误码说明
  4. [Error] Error parsing XML: unbound prefix
  5. php两种include加载文件方式效率比较如下
  6. CoreText 使用教程
  7. tomcat下jndi的三种配置方式
  8. JavaScript高级程序设计(第三版)学习笔记1~5章
  9. kinect for windows - 环境搭建
  10. 【Electron】Electron开发入门(八):自定义electron框架外壳(shell)的菜单(Menu)
  11. Java第六周学习总结
  12. Jmeter(七)_if控制器+循环控制器+计数器控制接口分支
  13. 【Linux】-NO.160.Linux.1 -【升级Centos7】
  14. 20175202 《Java程序设计》迭代和JDB
  15. TopK
  16. 2016_NENU_CS_3
  17. Visual Studio 由于缺少调试目标
  18. IOP知识点(5)
  19. 网络之XML解析-GData
  20. 通过Fiddler肆意修改接口返回数据进行测试

热门文章

  1. [树形DP]二叉苹果树
  2. java面试系列&lt;2&gt;——java容器
  3. Salesforce学习之路(七)Visualforce结合Reports展示图表
  4. python进阶(17)协程
  5. Mysql通配符的使用
  6. 1089 Insert or Merge
  7. CVPR2021 | 华为诺亚实验室提出Transformer in Transformer
  8. go gin框架和springboot框架WEB接口性能对比
  9. MySQL UDF提权执行系统命令
  10. MS06-040漏洞研究(中)【转载】