Mysql 监控脚本
#coding=utf-8
import jaydebeapi
import sys
import pymysql
import os
from prometheus_client import Gauge,start_http_server
import time
#hostname=v_host.read()
#hstname="".join(hostname)
#print(hostname.strip())
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()
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监控脚本
zabbix监控mysql时自定key用到的脚本 #!/usr/bin/env python #-*- coding: UTF-8 -*- from __future__ import print_f ...
- Zabbix Windos mysql 监控脚本
说明:判断mysql主进程是否关闭,如果关闭则返回0 创建文件:MySQL-ping.vbs Set objFS = CreateObject("Scripting.FileSystemOb ...
- 关于mysql和Apache以及nginx的监控脚本怎么写会比较好的记录
最近,自己业务进行上线,上线后,需要考虑的是对各种服务进行监控,包括(httpd服务,mysqld服务等),现在想以mysqld服务为例总结下那种方式的脚本最为专业和合理: (1).根据mysql的端 ...
- MySQL慢日志监控脚本实例剖析
公司线上的 MySQL 慢日志,之前一直没有做好监控.趁着上周空闲,我就把监控脚本写了下,今天特地把代码发出来与51博友分享一下. 针对脚本的注解和整体构思,我会放到脚本之后为大家详解. 1 2 3 ...
- centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobackupex/Xtrabackup 第四十节课
centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobacku ...
- centos 7中监控mysql 数据库脚本(监控端口)
centos 7中监控mysql 数据库脚本(监控端口) 监控mysql数据库的方法如下: 1.监控端口 netstat -nltp |grep 3306 2.监控进程 ps -ef |grep 33 ...
- MySQL的keepalived高可用监控脚本
MySQL的keepalived高可用监控脚本 MySQL(或者其它服务)的keepalived高可用监控脚本 开发脚本需求 :我们知道,keepalive是基于虚拟ip的存活来判断是否抢占maste ...
- shell监控脚本实例—监控mysql主从复制
分享一例shell脚本,用于监测mysql数据库的主从复制,有需要的朋友不妨参考学习下. 转自:http://www.jbxue.com/article/14103.html(转载请注明出处) 本节内 ...
- my34_脚本冥等添加自动任务-mysql监控部署
场景: 定义一套添加mysql监控的脚本,在mysql安装完毕后,一键执行添加监控 已有以下的等一系列命令可以读取mysql从库的延迟时间并推向influxdb,变化的部分为 -P 端口.-k k ...
随机推荐
- ch01 PHP开篇
ch01 PHP开篇 1.1启蒙知识 思考:WAMP是什么?:集成开发环境 [Windows+Apache服务器+MySQL数据库+PHP编程] 1.1.1 站点 将网站所有相关素材都放到一个文件夹中 ...
- caffe-ssd的GPU安装时make test 报错:.build_release/test/test_all.testbin:
报错原因:LIBRARIES路径添加不全 解决方法:LIBRARIES += glog gflags protobuf boost_system boost_filesystem boost_rege ...
- lua 特殊时间格式转换
[1]时间格式转换需求 工作中,因业务需要将时间格式进行转换.需求内容如下: 原格式:17:04:49.475 UTC Mon Mar 04 2019 转换格式:2019-03-04 17:04:4 ...
- <转>jmeter(二十三)分布式测试
本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...
- CRT/LCD/VGA Information and Timing
彩色阴极射线管的剖面图: 1. 电子QIANG Three Electron guns (for red, green, and blue phosphor dots)2. 电子束 Electron ...
- 单元测试系列之七:Sonar 数据库表关系整理一(rule相关)
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/7510072.html 简介:Sonar ...
- Python作业
1使用while 循环输入1,2,3,4,5,6,,8,9,10 count = 0 while count<10: count+=1 if count ==7: continue print( ...
- 5、zabbix使用进阶(01)
详细描述user parameters.定义主机发现规则实现自动发现.如何定义和实现自动注册方式 zabbix常用术语 1.主机(host):要监控的网络设备,可有IP或DNS名称指定: 2.主机组( ...
- 20165306 2017-2018-2《Java程序设计》课程总结
课程总结 每周作业链接汇总: 预备作业一:我期望的师生关系 预备作业二:学习基础和C语言基础调查 预备作业三:Linux安装与学习 第一周作业:Java入门 第二周作业:基本数据类型与数组,运算符.表 ...
- 数组toString()方法,数组常用操作
int[] arr ={1,2,3,4,5}; String arrString = Arrays.toString(arr); //输出[I@7150bd4d System.out.println( ...