linux监控dump文件产生,发送通知

操作系统:centos7.5

安装inotify-tools:

yum install inotify-tools

vi monitor.sh

#!/bin/bash
# 要监控的目录
DIRECTORY_TO_WATCH="/data/nfs/mservicelogs"
#机器人地址
webhook='https://xxx.xxx.com.cn/gateway/robot/webhook/send?yzjtype=0&yzjtoken=xxxx'
# 使用inotifywait来监控目录及其子目录下的文件创建事件
inotifywait -m -r -e create --format '%w%f' "$DIRECTORY_TO_WATCH" | while read NEW_FILE
do
    # 检查文件是否是hprof文件
    if [[ "$NEW_FILE" == *.hprof ]]; then
        date=`date +"%F %T"`
        # 发送通知,可以使用命令行工具如notify-send,或者其他通知方式
         curl $webhook -H 'Content-Type: application/json' -d "{
        'content': 'sit环境有服务内存溢出,dump文件生成!!!\n时间:${date}\n文件生成位置:${NEW_FILE}\n'}"
    fi
done

填写上面的内容到monitor.sh。

chmod 777 monitor.sh 

后台运行 nohup ./monitor.sh  > /dev/null &

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值