cat mysql_status_output.py
#coding=utf-8
import jaydebeapi
import sys
import pymysql
import os
from prometheus_client import Gauge,start_http_server
import time
#v_host=os.popen('echo $HOSTNAME')
#hostname=v_host.read()
#hstname="".join(hostname)
#print(hostname.strip())
class MySQL_Status_Output:
    def __init__(self,host,port,user,password):
        try:
            self.db = pymysql.connect(host=host,port=port,user=user,password=password)
            self.cursor = self.db.cursor()
        except Exception as e:
            print('Wrong')
            print(e)
    def mysql_status_select(self,x):
        try:
            sql='show global status like %s'
            data=x
            self.cursor.execute(sql,data)
            v_result=self.cursor.fetchall()
            return v_result
        except Exception as e:
            print(e)
    def mysql_select_sql(self,sql):
        try:
            self.cursor.execute(sql)
            v_result=self.cursor.fetchall()
            return v_result
        except Exception as e:
            print(e)
    def close(self):
        self.db.close()
if __name__ == "__main__":
    start_http_server(9400)
    mysqlGauge = Gauge('mysqlGauge','Description of gauge', ['mylabelname'])
    while True:
        try:
            time.sleep(1)
            pro_db = MySQL_Status_Output('127.0.0.1',3306,'dbadmin','dbadmin')
            my_result = pro_db.mysql_select_sql('select MONITOR_NAME from dbadmin.db_monitor_tab where status=1 and MONITOR_NAME is not null')
            for j in range(len(my_result)):
                monitor_name = "".join(tuple(my_result[j]))
                v_out = pro_db.mysql_status_select(monitor_name)
                for i in range(int(len(v_out))):
                    mysqlGauge.labels(mylabelname=v_out[i][0]).set(v_out[i][1])
            pro_db.close()
        except Exception as e:
            print('Is Wrong')
            print(e)

Mysql 监控脚本的更多相关文章

  1. MySQL监控脚本

    zabbix监控mysql时自定key用到的脚本 #!/usr/bin/env python #-*- coding: UTF-8 -*- from __future__ import print_f ...

  2. Zabbix Windos mysql 监控脚本

    说明:判断mysql主进程是否关闭,如果关闭则返回0 创建文件:MySQL-ping.vbs Set objFS = CreateObject("Scripting.FileSystemOb ...

  3. 关于mysql和Apache以及nginx的监控脚本怎么写会比较好的记录

    最近,自己业务进行上线,上线后,需要考虑的是对各种服务进行监控,包括(httpd服务,mysqld服务等),现在想以mysqld服务为例总结下那种方式的脚本最为专业和合理: (1).根据mysql的端 ...

  4. MySQL慢日志监控脚本实例剖析

    公司线上的 MySQL 慢日志,之前一直没有做好监控.趁着上周空闲,我就把监控脚本写了下,今天特地把代码发出来与51博友分享一下. 针对脚本的注解和整体构思,我会放到脚本之后为大家详解. 1 2 3 ...

  5. centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobackupex/Xtrabackup 第四十节课

    centos   shell编程6一些工作中实践脚本   nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志  直接送给bc做计算  gzip  innobacku ...

  6. centos 7中监控mysql 数据库脚本(监控端口)

    centos 7中监控mysql 数据库脚本(监控端口) 监控mysql数据库的方法如下: 1.监控端口 netstat -nltp |grep 3306 2.监控进程 ps -ef |grep 33 ...

  7. MySQL的keepalived高可用监控脚本

    MySQL的keepalived高可用监控脚本 MySQL(或者其它服务)的keepalived高可用监控脚本 开发脚本需求 :我们知道,keepalive是基于虚拟ip的存活来判断是否抢占maste ...

  8. shell监控脚本实例—监控mysql主从复制

    分享一例shell脚本,用于监测mysql数据库的主从复制,有需要的朋友不妨参考学习下. 转自:http://www.jbxue.com/article/14103.html(转载请注明出处) 本节内 ...

  9. my34_脚本冥等添加自动任务-mysql监控部署

    场景: 定义一套添加mysql监控的脚本,在mysql安装完毕后,一键执行添加监控   已有以下的等一系列命令可以读取mysql从库的延迟时间并推向influxdb,变化的部分为 -P 端口.-k k ...

随机推荐

  1. shell bash-shell

    bash shell中的命令替换,`cmd`或者$(cmd). bash shell中的变量赋值,直接name = var:  (bash中的变量赋值不能中间有空格) 变量引用时,$name,如果na ...

  2. Vue系列之 => 路由匹配

    路由基本使用,加动画切换 1 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  3. MB SD Connect Compact 5 Error 95.53392.0 Solved

    MB SD Connect Compact 5 is new released from MB Star company ,and its original version here the copy ...

  4. Linux笔记 #09# Tomcat多开以及Nginx负载均衡简单例子

    索引 Tomcat怎样多开.. 1.添加环境变量(最基础.关键的步骤!) 2.改catalina.sh 3.改相关端口 Nginx负载均衡简单例子 Tomcat怎样多开.. 演示一下如何开两个(开n个 ...

  5. 关于decode("utf-8")出现编码错的提示

    data = data.decode("utf-8") 出现错误时候可以加上第二个参数  如下; data = data.decode("utf-8",&quo ...

  6. tp剩余未验证内容-7

    bash脚本中 的 set -e表示 exit immediately if a simple command returns a non-zero value.主要是为了防止错误被忽略.会被立即退出 ...

  7. 【做题】agc016d - XOR Replace——序列置换&环

    原文链接 https://www.cnblogs.com/cly-none/p/9813163.html 题意:给出初始序列\(a\)和目标序列\(b\),都有\(n\)个元素.每次操作可以把\(a\ ...

  8. Mac OS X 清除DNS缓存

    参考: Flushing your DNS cache in Mac OS X and Linux Mac OS X 清除DNS缓存 根据Mac OS X操作系统的版本选择以下命令: Mac OS X ...

  9. 数组中的stdClass Object如何访问

    使用print_r($data)输出结果为 Array ( [0] => stdClass Object ( [color_item_no] => 1 [color_name] => ...

  10. Springboot静态文件不更新的解决办法,以及Springboot实现热部署

    Springboot静态文件不更新的解决办法,以及Springboot实现热部署 原文链接:https://www.cnblogs.com/blog5277/p/9271882.html 原文作者:博 ...