• Zabbix 自定义report


    #!/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],"	",$5,"	",$6}' $logdir/cpu$month.txt $logdir/mem$month.txt >$logdir/result$month.txt
    sed -i '1i Month	Group name	Host	Cpu_avg_Unitil	Cpu_Max_Unitil	Mem_Avg_usage	Mem_Max_Usage' $logdir/result$month.txt
    
    rm -rf $logdir/cpu$month.txt
    rm -rf $logdir/mem$month.txt
    

      

  • 相关阅读:
    [51nod1685]第k大区间
    [51nod1515]明辨是非
    centos中jdk配置 平凡的人生
    centos中apachetomcat的配置 平凡的人生
    centos6.5中gitlab的搭建 平凡的人生
    centos精简系统 源码安装客户端git 平凡的人生
    Vue学习笔记vue调试工具vuedevtools安装及使用
    Django Admin 实现三级联动的示例代码(省市区)===>小白级
    Vue学习笔记基于CDN引入方式简单前后端分离项目学习(Vue+Element+Axios)
    Django Admin 配置和定制基本功能(基本二次开发配置)
  • 原文地址:https://www.cnblogs.com/xingfuxiaokong/p/13724628.html
Copyright © 2020-2023  润新知