nagios 监控 mysql 读写比 R/W
为什么80%的码农都做不了架构师?>>>
#!/usr/bin/python2.7
# -*- coding:utf-8 -*-
from optparse import OptionParser
import commands,sys,jastme,re
from datetime import datetime
"""Nagios plugin to report the mysql R/W Ratioauthor jastme
"""parser = OptionParser(usage="%prog -w <warning threshold> -c <critical threshold> [ -h ]\n\nBefore use the script,please execute 'grant usage on *.* to monitor@'127.0.0.1' identified by 'monitor';\nflush privileges",version="%prog ")parser.add_option("-w", "--warning",action="store", type="string", dest="warn_threshold", help="Warning threshold in percentage")parser.add_option("-c", "--critical",action="store", type="string", dest="crit_threshold", help="Critical threshold in percentage")(options, args) = parser.parse_args()class Monitor:def __init__(self,username,password,hostname,port):""" you can call sam var here """self.username = usernameself.password = passwordself.port = portself.hostname = hostnamedef __Qcache_hits(self,):R=commands.getoutput(''' mysql -u%s -p%s -h%s -P%s -e "show global status like 'Qcache_hits'" | grep -Po "\d+" ''' %(self.username,self.password,self.hostname,self.port))return Rdef __Com_select(self):R=commands.getoutput(''' mysql -u%s -p%s -h%s -P%s -e "show global status like 'Com_select'" | grep -Po "\d+" ''' %(self.username,self.password,self.hostname,self.port))return Rdef __Com_insert(self):R=commands.getoutput(''' mysql -u%s -p%s -h%s -P%s -e "show global status like 'Com_insert'" | grep -Po "\d+" ''' %(self.username,self.password,self.hostname,self.port))return Rdef __Com_update(self):R=commands.getoutput(''' mysql -u%s -p%s -h%s -P%s -e "show global status like 'Com_update'" | grep -Po "\d+" ''' %(self.username,self.password,self.hostname,self.port))return Rdef __Com_delete(self):R=commands.getoutput(''' mysql -u%s -p%s -h%s -P%s -e "show global status like 'Com_delete'" | grep -Po "\d+" ''' %(self.username,self.password,self.hostname,self.port))return Rdef __Com_replace(self):R=commands.getoutput(''' mysql -u%s -p%s -h%s -P%s -e "show global status like 'Com_replace'" | grep -Po "\d+" ''' %(self.username,self.password,self.hostname,self.port))return Rdef __doit(self):_Qcache_hits = int(re.findall(r"\d+",self.__Qcache_hits())[0])_Com_select = int(re.findall(r"\d+",self.__Com_select())[0])_Com_insert = int(re.findall(r"\d+",self.__Com_insert())[0])_Com_update = int(re.findall(r"\d+",self.__Com_update())[0])_Com_delete = int(re.findall(r"\d+",self.__Com_delete())[0])_Com_replace = int(re.findall(r"\d+",self.__Com_replace())[0])R = ( _Com_select + _Qcache_hits) / ( _Com_insert + _Com_update + _Com_delete + _Com_replace ) * 100return Rdef Result(self):R = self.__doit()print "R/W Ratio is %d | R/W Ratio=%d" %(R,R) if __name__ == "__main__":username = "monitor"password = str(jastme.decrypt(119,u'NALBOBJBCBHAGBOA'))hostname = "127.0.0.1"port = "3369"Monitor(username,password,hostname,port).Result()
转载于:https://my.oschina.net/jastme/blog/496892
nagios 监控 mysql 读写比 R/W相关推荐
- nagios监控mysql(check_mysql)及内存使用率(check_mem)
一.监控本地(localhost)内存 1.上传监控脚本 check_mem 到/usr/local/nagios/libexec # chown -R nagios.nagios check_mem ...
- nagios监控mysql服务_nagios监控mysql及邮件报警
1.使用默认监控命令check_http命令+相关的参数来实现,如下: 在command.cfg添加如下关键词监控命令:check_http_word,参数解析:-I指定IP或者主机名,-u指定URL ...
- nagios监控mysql主从
为什么80%的码农都做不了架构师?>>> nagios监控mysql的主从,我这里介绍两种方法,一种是用nagios自带监控mysql 的插件实现,另一种是自己写脚本,下面是两 ...
- nagios监控mysql服务_nagios监控mysql服务
配置被监控端 1.安装check_mysql插件 nagios 监控 mysql 需要用到 check_mysql 和 check_mysql_query 两个插件. 安装完成 nagios 后,发现 ...
- nagios监控mysql主机,nginx,cpu,网卡流量
nagios安装完成,打开/usr/local/nagios/etc/nagios.cfg去掉cfg_dir=/usr/local/nagios/etc/servers前面的#号,并创建/usr/lo ...
- nagios监控mysql主从复制
环境: Centos5.6 mysql只做同步指定库,没有同步mysql库用户数据 登陆从服务器mysql,添加验证的用户 grant replication client on *.* to 'sl ...
- nagios监控mysql
首先下载目前最高的版本 http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15 ...
- nagios监控 mysql 表结构
引言 为了给客户演示对mysql表结构的监控,在搜了很久之后发现不得不自己写一个脚本了.percona这么牛B的公司竟然没有提供一个这方面的工具,看来客户的要求有点花儿不实啊...这个问题一共花费了我 ...
- nagios使用check_mysql监控mysql
nagios监控mysql服务器: 在被监控机上 1.建立专用数据库: [root@svr3 ~]# /usr/local/webserver/mysql/bin/mysql -u root -p E ...
最新文章
- C++类的构造函数不能为虚函数的原因
- Spring中应用反射机制浅析
- 压缩可以卸载吗_不可错过!螺杆压缩机故障分析详解(2)
- panda.read_csv的常用参数说明
- 洛谷P2497:基站建设(splay、斜率优化)
- python plot map_使用matplotlibbasemap在边界打印
- javascript中依赖属性(Dependency Property)的实现
- nyoj 239 月老的难题
- 看过无数 Java GC 文章,这 5 个问题你也未必知道!
- MySQL事务及隔离级别详解
- 伺服系统 计算机仿真,减摇鳍电伺服系统的计算机仿真研究-应用科技-哈尔滨工程大学.PDF...
- Python爬虫方法三部曲
- 方法论 | 多因子策略的五大讨论(思维导图收藏版)
- 【回波损耗(dB)和电压驻波比(VSWR)之间的关系】
- java拍照控件焦距问题,监控摄像头镜头焦距计算方法
- SpringSecurity框架用法简介
- putty使用SSH密钥登录Linux实例
- pyqt5中sender方法介绍_PyQt5学习记录(二):Event sender
- Nginx 负载均衡动静分离配置
- 极客日报第131期:华为将正式发布鸿蒙手机操作系统;清华成立量子信息班;美团:外卖是微利业务,直接降低抽成无法持续