zoukankan      html  css  js  c++  java
  • zabbix--高级篇-监控docker服务(一)

    一,配置zabbix 客户端环境

    rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
    yum install zabbix-agent -y
    vim /etc/zabbix/zabbix_agentd.conf
    ##需要改变的内容
    PidFile=/var/run/zabbix/zabbix_agentd.pid
    LogFile=/var/log/zabbix/zabbix_agentd.log
    LogFileSize=0
    Server=192.168.0.214
    ServerActive=192.168.0.214
    Hostname=k8s1
    HostMetadataItem=system.uname
    Include=/etc/zabbix/zabbix_agentd.d/*.conf

    systemctl restart zabbix-agent.service

    二,配置脚本

      

    [root@k8s1 alertscripts]# cat docker.py
    #!/usr/bin/python
    import sys
    import os
    import json
    
    
    def discover():
        d = {}
        d['data'] = []
        with os.popen("docker ps -a --format {{.Names}}") as pipe:
            for line in pipe:
                info = {}
                info['{#CONTAINERNAME}'] = line.replace("
    ","")
                d['data'].append(info)
    
        print json.dumps(d)
    
    
    def status(name,action):
        if action == "ping":
            cmd = 'docker inspect --format="{{.State.Running}}" %s' %name
            result = os.popen(cmd).read().replace("
    ","")
            if result == "true":
                print 1
            else:
                print 0
        else:
            cmd = 'docker stats %s --no-stream --format "{{.%s}}"' % (name,action)
            result = os.popen(cmd).read().replace("
    ","")
            if "%" in result:
                print float(result.replace("%",""))
            else:
                print result
    
    
    if __name__ == '__main__':
            try:
                    name, action = sys.argv[1], sys.argv[2]
                    status(name,action)
            except IndexError:
                    discover()
    UserParameter=docker.discovery,/usr/lib/zabbix/alertscripts/docker.py
    UserParameter=docker.[*],/usr/lib/zabbix/alertscripts/docker.py $1 $2

    https://www.cnblogs.com/binglansky/p/9132714.html

  • 相关阅读:
    [转]C#读写app.config中的数据
    [转]DirectoryEntry的应用
    js读取xml文档,并实现简单分页
    [转]写给想要做产品经理的同学
    《算法导论》(第二章)算法入门
    《算法导论》中伪代码的约定
    HDU ACM 1284 钱币兑换问题
    《算法导论》(第一部分)(第一章)
    HDU ACM 4554 叛逆的小明
    HDU ACM 1002 A + B Problem II
  • 原文地址:https://www.cnblogs.com/kingle-study/p/10560319.html
Copyright © 2011-2022 走看看