首页 > 其他分享 >zabbix自定义监控

zabbix自定义监控

时间:2022-09-07 08:35:46浏览次数:58  
标签:httpd log 自定义 zabbix 监控 root check localhost

zabbix自定义监控
自定义监控进程
测试监控httpd,需要在监控端部署httpd,以方便监控
``

配置监控脚本

#在监控端
[root@localhost ~]# dnf -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# ss -anlt | grep 80
LISTEN 0      128                *:80               *:*   

#编写脚本
[root@localhost ~]# mkdir /scripts
[root@localhost ~]# vim /scripts/check_process.sh
#!/bin/bash

count=$(ps -ef|grep -Ev "grep|$0" | grep $1 | wc -l)
if [  $count -eq 0 ];then
        echo '1'
else
        echo '0'
fi
[root@localhost ~]# chmod +x /scripts/check_process.sh 
[root@localhost ~]# ll /scripts/check_process.sh
-rwxr-xr-x. 1 root root 119 Sep  6 21:09 /scripts/check_process.sh

#在监控端,修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UnsafeUserParameters=check_process[*],/bin/bash /scripts/check_process.sh $1

#服务端检查key是否可用
[root@zabbix ~]# zabbix_get -s 192.168.111.137 -k check_process[httpd]
0
[root@zabbix ~]# zabbix_get -s 192.168.111.137 -k check_process[mysql]
1
[root@zabbix ~]# zabbix_get -s 192.168.111.137 -k check_process[zabbix]
0

添加监控项


查看监控数据

添加触发器



手动关闭httpd,进行测试触发报警

[root@localhost ~]# systemctl stop httpd

查看报错

发送邮件

查看邮件

自定义监控日志
初学者复制的脚本
忘情的log脚本日志

#由于是python的脚本,需要在python环境中
[root@localhost ~]# dnf -y install python36

#编写脚本
[root@localhost ~]# cd /etc/scripts/
[root@localhost scripts]# vim log.py
#!/usr/bin/env python3
import sys
import re

def prePos(seekfile):
    global curpos
    global curpos
    try:
        cf = open(seekfile)
    except IOError:
        curpos = 0
        return curpos
    except FileNotFoundError:
        curpos = 0
        return curpos
    else:
        try:
            curpos = int(cf.readline().strip())
        except ValueError:
            curpos = 0
            cf.close()
            return curpos
        cf.close()
    return curpos

def lastPos(filename):
    with open(filename) as lfile:
        if lfile.readline():
            lfile.seek(0,2)
        else:
            return 0
        lastPos = lfile.tell()
    return lastPos

def getSeekFile():
    try:
        seekfile = sys.argv[2]
    except IndexError:
        seekfile = '/tmp/logseek'
    return seekfile

def getKey():
    try:
        tagKey = str(sys.argv[3])
    except IndexError:
        tagKey = 'Error'
     return tagKey

 def getResult(filename,seekfile,tagkey):
     destPos = prePos(seekfile)
     curPos = lastPos(filename)

     if curPos < destPos:
         curpos = 0

    try:
        f = open(filename)
    except IOError:
        print('Could not open file: %s' % filename)
    except FileNotFoundError:
        print('Could not open file: %s' % filename)
    else:
        f.seek(destPos)

        while curPos != 0 and f.tell() < curPos:
            rresult = f.readline().strip()
            global result
            if re.search(tagkey, rresult):
                result = 1
                break
            else:
                result = 0

        with open(seekfile,'w') as sf:
            sf.write(str(curPos))
        finally:
            f.close()
        return result

if __name__ == "__main__":
    result = 0
    curpos = 0
    tagkey = getKey()
    seekfile = getSeekFile()
    result = getResult(sys.argv[1],seekfile,tagkey)
    print(result)
[root@localhost scripts]# chmod +x log.py 
[root@localhost scripts]# ll
total 12
-rwxr-xr-x. 1 root root  128 Sep  6 21:53  check_process.sh
-rwxr-xr-x. 1 root root 1890 Sep  6 22:49  log.py

#修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_logs[*],/etc/scripts/log.py $1 $2 $3
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd 

#需要给/var/log/httpd目录添加权限
[root@localhost ~]# chmod 755 /var/log/httpd/
[root@localhost ~]# ll /var/log/httpd/
total 8
-rw-r--r--. 1 root root  704 Sep  6 21:42 access_log
-rw-r--r--. 1 root root 2635 Sep  6 22:12 error_log
#给httpd的error日志,添加一个错误信息
[root@localhost ~]# echo "Error" >> /var/log/httpd/error_log
#服务端测试
[root@zabbix ~]# zabbix_get -s 192.168.111.137 -k check_logs['/var/log/httpd/error_log']
1
[root@zabbix ~]# zabbix_get -s 192.168.111.137 -k check_logs['/var/log/httpd/error_log']
0

添加监控项



添加触发器


手动添加错误日志,触发报警

[root@localhost httpd]# echo "Error123" >> /var/log/httpd/error_log 

标签:httpd,log,自定义,zabbix,监控,root,check,localhost
From: https://www.cnblogs.com/soap-bubble/p/16663992.html

相关文章

  • zabbix自定义监控进程与日志
    zabbix自定义监控进程与日志目录zabbix自定义监控进程与日志zabbix自定义监控进程zabbix自定义监控日志zabbix自定义监控进程基于之前的邮箱告警,部署完成后,我们在zabbi......
  • Java 监控直播流rtsp协议转rtmp、hls、httpflv协议返回浏览器
    Java监控直播流rtsp协议转rtmp、hls、httpflv协议返回浏览器目录需求背景:一:了解音视频流协议:二:方案一rtsp转rtmp1、下载nginx+nginx-rtmp-module2、nginx配置文件3、......
  • 【WPF】自定义用登入界面 (C#) -从认证和授权说起。
    概要自定义如下界面登入界面WPF桌面软件。写代码时候要注意哪些事情呢?答案:认证和授权。  我们在桌面应用软件登入界面时,作为小白一般都是用明文密码登入软件然后就......
  • zabbix自定义监控进程和日志
    zabbix自定义监控进程和日志目录zabbix自定义监控进程和日志自定义监控进程配置监控脚本添加监控项添加触发器手动关闭httpd服务,触发报警自定义监控日志服务端和客户端操......
  • 【uni-app】自定义导航栏/标题栏
    什么是自定义导航栏默认导航栏或原生导航栏是啥样的,你懂的。但,我想给导航栏加个背景图,比如这样: 这时候就需要自定义导航栏。自定义导航栏自定义导航栏的中心思想是: ......
  • client-go开发自定义operator
    开发operator一共分为5步骤一、创建configconfig的创建有两种方式1、clientcmd.BuildConfigFromFlagsconfig,err:=clientcmd.BuildConfigFromFlags("",clientcmd.......
  • idea自动生成实体类,自动添加注释,自定义实体类
    之前写过一篇博客记录了idea编译器怎么快速生成实体类,但是发现没有自动添加注释,如果字段比较多的话,看着很不友好:https://www.cnblogs.com/lyd447113735/p/14924011.html所......
  • 组件的自定义事件和原生事件、组件的嵌套
    原生事件在原生组件(就是html标签)中事件是由系统来设计触发条件的:<div@click="fn">点我</div> 自定义事件在自定义组件中,事件是由自己来设计什么时候触发的......
  • 【MongoDB】Prometheus监控MongoDB
    这里只是写了如何安装mongodb_exporter。其他部分参看:https://www.cnblogs.com/abclife/p/16659151.html下载和安装sudowgethttps://github.com/percona/mongodb_exp......
  • java调用kettle自定义kettle.properties配置文件路径
    java调用kettle自定义kettle.properties配置文件路径默认路径java调用kettle的jar包时,在初始化环境的时候,会在指定路径创建并加载kettle的kettle.properties文件,该文件的......