企业微信机器人-监控磁盘和应用可用率-内存CPU

1.每10分钟执行一次

*/10 * * * * /opt/shell/check_disk.sh

2.脚本内容

复制代码
for i in `cat /opt/shell/hosts`
do
#    echo $i
    sys=`ssh $i "df -h |grep '\/$'"`
#echo $sys
    sysc=`echo ${sys}|awk -F ' |%' '{print $5}'`
#echo $sysc
    if [[ $sysc -gt 85  ]];then
        curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=348wo935-shia-4939-a311-dc221d4sb6c4' \
   -H 'Content-Type: application/json' \
   -d '
{
    "msgtype": "markdown",
    "markdown": {
        "content": "<font color=\"warning\">'$i'</font>的系统磁盘使用率大于85,当前使用率为'${sysc}'%,请及时处理!!"
    }
}'
    fi
    data=`ssh $i "df -h |egrep '\/mnt|\/data'"`
#echo $data
    datac=`echo ${data}|awk -F ' |%' '{print $5}'`
    if [[ $datac -gt 85  ]];then
        curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=3482ni35-9a1a-4shi9-a311-dc2sbd4766c4' \
   -H 'Content-Type: application/json' \
   -d '
{
    "msgtype": "markdown",
    "markdown": {
        "content": "<font color=\"warning\">'$i'</font>的数据磁盘使用率大于85,当前使用率为'${datac}'%,请及时处理!!"
    }
}'
    fi
done
复制代码

 2.http响应时间监控告警

复制代码
[root@VM_0_11_centos shell]# cat checklong_http_code.sh 
#!/bin/bash
while true
do
    for i in `cat services_list`
    do
        http_code=`curl -I -o /dev/null -m 10 -s -w %{http_code} $i`
        if [[ $http_code -ne 200 && $http_code -ne 302 ]]
        then
            date
            echo "$i is down"
            curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=348wo935-9sha-4i39-a311-dc2sb21d4766c4' \
   -H 'Content-Type: application/json' \
   -d '
{
    "msgtype": "markdown",
    "markdown": {
        "content": "<font color=\"warning\">'$i'</font>服务状态超长时间(10s)返回异常,请快速检查!!"
    }
}'
        fi
    done
    sleep 30
done
[root@VM_0_11_centos shell]# 
复制代码

 3.内存cpu

复制代码
[dev@VM_0_11_centos shell]$ cat  /opt/shell/check_memcpu.sh 
function baojing(){
curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=348wo935-shia-4939-a311-dc221dsb66c4' \
   -H 'Content-Type: application/json' \
   -d '
   {
        "msgtype": "markdown",
        "markdown": {
            "content": "<font color=\"warning\">'$1'</font>"
        }
   }'

}
for i in `cat hosts`;do
#############检查内存情况
meminfo=`ssh $i "free -m|sed -n '2p'"`
mem=`echo $meminfo|awk '{print $3/$2*100}'|awk -F'.' '{print $1}'`
#echo $mem
if [ $mem -gt 85 ];then
    baojing "服务器${i}的内存使用率大于85%,当前使用率为$mem%"
fi

#############检查cpu情况
cpuinfo=`ssh $i "mpstat 1 1|tail -n 1"`
cpu=`echo $cpuinfo|awk '{print $3+$5}'|awk -F'.' '{print $1}'`
echo $cpu
#echo $mem
if [ $cpu -gt 85 ];then
    baojing "服务器${i}的cpu使用率大于85%,当前使用率为$cpu%"
fi
done
复制代码
[dev@VM_0_11_centos shell]$ cat hosts 
10.0.0.28
10.0.0.24
10.0.0.29
10.0.0.12
10.0.0.30
10.0.0.17

 

posted @   littlevigra  阅读(517)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
历史上的今天:
2019-08-22 (转)利用Beautiful Soup去抓取p标签下class=jstest的内容
点击右上角即可分享
微信分享提示