首页 / MYSQL / Mysql 监控脚本
Mysql 监控脚本
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Mysql 监控脚本,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1869字,纯文字阅读大概需要3分钟。
内容图文
![Mysql 监控脚本](/upload/InfoBanner/zyjiaocheng/913/aea0eb62970d4b56b70f7ebf5a6af7ca.jpg)
#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 监控脚本全部内容,希望文章能够帮你解决Mysql 监控脚本所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】