利用prometheus 客户端采集磁盘容量脚本

点击查看代码
#!/bin/bash
#date: 20220621
#author:bin
>/tmp/node_dmz.txt
>/tmp/node_err.txt
>/tmp/devicecheck.txt

[ -f /tmp/node_dmz.txt ]||touch /tmp/node_dmz.txt
[ -f /tmp/node_err.txt ]||touch /tmp/node_err.txt
[ -f /tmp/devicecheck.txt ]||touch /tmp/devicecheck.txt

while  read line 
do
    {
     ping -c1 -W1 $line &>/dev/null
     if [ $? -ne 0 ];then
           echo $line >>/tmp/node_err.txt
           continue 
     fi 
     curl -s --continue-timeout 1 $line:49999/metrics   &>/dev/null   #49999 是服务器prometheus监听的端口
     if [ $? -eq 28 ];then
          echo $line >>/tmp/node_dmz.txt
          continue
     fi
     curl $line:49999/metrics |grep node_filesystem_size_bytes |grep /bankapp &>/dev/null
     if [ $? -ne 0 ];then
         continue
     fi
     capacity=`curl $line:49999/metrics |grep node_filesystem_size_bytes |grep /bankapp|awk '{print $NF}'`
     echo '主机  $line 磁盘分区异常... /bankapp 磁盘容量为: $ capacity' >>/tmp/devicecheck.txt
    }&
    sleep 0.1

 done</tmp/node.txt
posted @ 2022-06-22 09:59  zbzSH  阅读(209)  评论(0)    收藏  举报