获取日志告警
AI-摘要
KunKunYu GPT
AI初始化中...
介绍自己
生成本文简介
推荐相关文章
前往主页
前往tianli博客
1 主配置文件
vim /etc/zabbix/zabbix_agentd.d/userparameter_application.conf
UserParameter=common.error[*],/usr/bin/python3 /usr/local/src/zabbix/scripts/pl-monitor-scripts/common_error_count.py $1 $2 $3 $4 $5
2 传参文件
cat > /usr/local/src/zabbix/scripts/pl-monitor-scripts/common_error_count.py << 'EOF'
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import main_module
import utils
import time
import sys
try:
access_log_file = sys.argv[1]
row_number_file = sys.argv[2]
host_name = sys.argv[3]
module = sys.argv[4]
max_row_number = sys.argv[5]
except Exception as e:
pass
LOG = utils.get_logger()
# (access_log_file, row_number_file, module, target_method_file, max_row_number, host_name) = main_module.get_in_param(LOG)
LOG.info("common_error获取参数:")
LOG.info('获取传入参数:access_log_file=%s,row_number_file=%s,module=%s,max_row_number=%s,host_name=%s', access_log_file, row_number_file, module, str(max_row_number), host_name)
time_start = time.time()
(log_list, new_log_number) = main_module.get_log_content_list(row_number_file, access_log_file, max_row_number, LOG)
#print(log_list)
# main_module.check_new_log_number(time_start, new_log_number, module, LOG)
error_log = [log.decode() for log in log_list if "ERROR" in log.decode()]
count_errors = len(error_log)
print("count:%s,ERROR:%s" % (str(count_errors), str(error_log[0:5])))
time_end = time.time()
time_spent = int(time_end - time_start)
LOG.info('脚本执行结束!耗时:%s', str(time_spent))
EOF
3 具体日志
cat > /usr/local/src/zabbix/scripts/pl-monitor-scripts/test.sh << 'EOF'
#!/bin/bash
ms=$(date +%H:%M)
k=" "
usercenter_error_log="/xxx/logs/common-error.log"
usercenter_record="/dev/shm/微服务名称_common-error.txt"
usercenter_old=`cat /dev/shm/微服务名称_common-error.txt`
current_time=`stat $usercenter_error_log |grep Change|awk -F " " '{print $2$3}'`
if [ ${current_time} == ${usercenter_old} ];then
echo ""
else
stat $usercenter_error_log |grep Change|awk -F " " '{print $2$3}' >${usercenter_record}
echo "`grep -5 "ERROR" ${usercenter_error_log}|grep -v "c.h.i.m.schedule.message"|grep $k$ms`"
fi
EOF
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
作者编辑不易,如有转载请注明出处。完整转载来自https://wangairui.com 网站名称:猫扑linux
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果