zoukankan      html  css  js  c++  java
  • 自定义监控

    监控ELK集群状态python脚本

    [root@elk-s1 ~]# vim /etc/zabbix/zabbix_agentd.d/els_status.py
    #!/usr/bin/env python
    #coding:utf-8
    #Author xuanlv
    
    import subprocess
    false="false"
    obj = subprocess.Popen(("curl -sXGET http://10.20.3.128:9200/_cluster/health?
    pretty=true"),shell=True, stdout=subprocess.PIPE)
    data = obj.stdout.read()
    data1 = eval(data)
    status = data1.get("status")
    if status == "green":
        print "100"
    else:
        print "50"
    

    授权

    [root@elk-s1 ~]# chmod a+x /etc/zabbix/zabbix_agentd.d/els_status.py
    

    监控Redis列表长度脚本

    [root@redis ~]# cat /etc/zabbix/zabbix_agentd.d/redis_llen.py
    #!/usr/bin/env python
    #coding:utf-8
    #Author xuanlv
    import redis
    def redis_conn():
        pool=redis.ConnectionPool(host="10.20.0.252",port=6379,db=0)
        conn = redis.Redis(connection_pool=pool)
        data = conn.llen('api4-nginx-accesslog')
        print(data)
    redis_conn()
    

    授权

    [root@redis ~]# chmod a+x /etc/zabbix/zabbix_agentd.d/redis_llen.py
    

    监控MongodbDB复制集状态

    [root@redis ~]# cat /etc/zabbix/zabbix_agentd.d/mongodb_cluster_monitor.py
    #!/bin/env python
    #coding:utf-8
    #Author: xuanlv
    
    import subprocess
    success_list = []
    error_list= []
    def get_mongodb_status():
        obj = subprocess.Popen(("echo 'rs.status()' | /usr/local/mongodb/bin/mongo -u user -p wswd --authenticationDatabase admin 
    | grep health | awk -F':' '{print $2}' | awk -F',' '{print $1}'"),shell=True,
    stdout=subprocess.PIPE)
        restful = obj.stdout.read()
        data = restful.split()
        for i in data:
            if i == "1":
                success_list.append(i)
            else:
                error_list.append(i)
                
    def count_status():
        if len(error_list) > 0:
            print 100
        else:
            print 50
    def main():
        get_mongodb_status()
        count_status()
    if __name__ == "__main__":
        main()
    

    授权

    [root@redis ~]# chmod a+x /etc/zabbix/zabbix_agentd.d/redis_llen.py
    

    kubernetes 集群状态监控脚本

    [root@kubernetes-master1 ~]# cat /etc/zabbix/zabbix_agentd.d/k8s_monitor.py
    #!/usr/bin/env python
    #coding:utf-8
    #Author xuanlv
    
    import subprocess
    success_list = []
    error_list= []
    def get_status():
        obj = subprocess.Popen(("curl -sXGET http://10.20.15.209:8080/api/v1/nodes"),shell=True, stdout=subprocess.PIPE)
        data = obj.stdout.read()
        data1 = eval(data)
        data2 = data1.get('items')
        #print data2
        for i in data2:
            data3 = i.get('status')
            for i in data3.get('conditions'):
                if i.get('reason') == 'KubeletReady':
                    if i.get('type') == "Ready":
                        if i.get('status') == 'True':
                            success_list.append(i.get('status'))
                        elif i.get('status') == 'False':
                            error_list.append(i.get('status'))
                        else:
                            break
                    else:
                        error_list.append(i.get('status'))
                        #pass
                else:
                    error_list.append(i.get('status'))
    def count_status():
        if len(error_list) == 0:
            print 50
        else:
            print 100
    def main():
        get_status()
        count_status()
    if __name__ == "__main__":
        main()
    

    授权

    [root@kubernetes-master1 ~]# chmod a+x /etc/zabbix/zabbix_agentd.d/k8s_monitor.py
    

    监控RabbitMQ集群节点状态

    python脚本
    
    [root@zabbix-web02 ~]# cat /etc/zabbix/zabbix_agentd.d/rabbit_cluster_monitor.py
    #!/bin/env python
    #coding:utf-8
    #Author: xuanlv
    
    import subprocess
    running_list = []
    error_list = []
    false="false"
    true="true"
    def get_status():
        obj = subprocess.Popen(("curl -sXGET -u guest:guest http://10.20.3.171:15671/api/nodes"),shell=True, stdout=subprocess.PIPE)
        data = obj.stdout.read()
        data1 = eval(data)
        for i in data1:
            if i.get("running") == "true":
                running_list.append(i.get("name"))
            else:
                error_list.append(i.get("name"))
    def count_server():
        if len(running_list) < 3: #可以判断错误列表大于0或者运行列表小于3,3未总计的节点数量
            print 100 #100就是集群内有节点运行不正常了
        else:
            print 50 #50为所有节点全部运行正常
    def main():
        get_status()
        count_server()
    if __name__ == "__main__":
        main()
    

    授权

    [root@zabbix-web02 ~]# chmoa a+x /etc/zabbix/zabbix_agentd.d/rabbit_cluster_monitor.py
    
  • 相关阅读:
    (转载)Android content provider基础与使用
    如何解决Android的SDK与ADT不匹配问题
    Android 中断线程的处理
    用AsyncTask 来实现下载图片在android开发中
    开源自己的一个小android项目(美女撕衣服游戏)
    实现在Android开发中的Splash Screen开场屏的效果
    支持在安卓中UI(View)的刷新功能
    android从资源文件中读取文件流显示
    后缀数组 模板题 hdu1403(最长公共(连续)子串)
    Codeforces Round #383 (Div. 1) C(二分图)
  • 原文地址:https://www.cnblogs.com/xuanlv-0413/p/15171568.html
Copyright © 2011-2022 走看看