为什么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相关推荐

  1. nagios监控mysql(check_mysql)及内存使用率(check_mem)

    一.监控本地(localhost)内存 1.上传监控脚本 check_mem 到/usr/local/nagios/libexec # chown -R nagios.nagios check_mem ...

  2. nagios监控mysql服务_nagios监控mysql及邮件报警

    1.使用默认监控命令check_http命令+相关的参数来实现,如下: 在command.cfg添加如下关键词监控命令:check_http_word,参数解析:-I指定IP或者主机名,-u指定URL ...

  3. nagios监控mysql主从

    为什么80%的码农都做不了架构师?>>>    nagios监控mysql的主从,我这里介绍两种方法,一种是用nagios自带监控mysql 的插件实现,另一种是自己写脚本,下面是两 ...

  4. nagios监控mysql服务_nagios监控mysql服务

    配置被监控端 1.安装check_mysql插件 nagios 监控 mysql 需要用到 check_mysql 和 check_mysql_query 两个插件. 安装完成 nagios 后,发现 ...

  5. nagios监控mysql主机,nginx,cpu,网卡流量

    nagios安装完成,打开/usr/local/nagios/etc/nagios.cfg去掉cfg_dir=/usr/local/nagios/etc/servers前面的#号,并创建/usr/lo ...

  6. nagios监控mysql主从复制

    环境: Centos5.6 mysql只做同步指定库,没有同步mysql库用户数据 登陆从服务器mysql,添加验证的用户 grant replication client on *.* to 'sl ...

  7. nagios监控mysql

    首先下载目前最高的版本 http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15 ...

  8. nagios监控 mysql 表结构

    引言 为了给客户演示对mysql表结构的监控,在搜了很久之后发现不得不自己写一个脚本了.percona这么牛B的公司竟然没有提供一个这方面的工具,看来客户的要求有点花儿不实啊...这个问题一共花费了我 ...

  9. nagios使用check_mysql监控mysql

    nagios监控mysql服务器: 在被监控机上 1.建立专用数据库: [root@svr3 ~]# /usr/local/webserver/mysql/bin/mysql -u root -p E ...

最新文章

  1. C++类的构造函数不能为虚函数的原因
  2. Spring中应用反射机制浅析
  3. 压缩可以卸载吗_不可错过!螺杆压缩机故障分析详解(2)
  4. panda.read_csv的常用参数说明
  5. 洛谷P2497:基站建设(splay、斜率优化)
  6. python plot map_使用matplotlibbasemap在边界打印
  7. javascript中依赖属性(Dependency Property)的实现
  8. nyoj 239 月老的难题
  9. 看过无数 Java GC 文章,这 5 个问题你也未必知道!
  10. MySQL事务及隔离级别详解
  11. 伺服系统 计算机仿真,减摇鳍电伺服系统的计算机仿真研究-应用科技-哈尔滨工程大学.PDF...
  12. Python爬虫方法三部曲
  13. 方法论 | 多因子策略的五大讨论(思维导图收藏版)
  14. 【回波损耗(dB)和电压驻波比(VSWR)之间的关系】
  15. java拍照控件焦距问题,监控摄像头镜头焦距计算方法
  16. SpringSecurity框架用法简介
  17. putty使用SSH密钥登录Linux实例
  18. pyqt5中sender方法介绍_PyQt5学习记录(二):Event sender
  19. Nginx 负载均衡动静分离配置
  20. 极客日报第131期:华为将正式发布鸿蒙手机操作系统;清华成立量子信息班;美团:外卖是微利业务,直接降低抽成无法持续

热门文章

  1. 我的代码为什么看起来像shit?
  2. 14、mybatis多表关联查询 association定义关联对象封装规则及懒加载
  3. discuz 的 group.php,DiscuzX用户组过期问题解决方法
  4. eclipse java参数类型_JAVA第二天笔记--eclipse使用/数据类型转换
  5. 互斥锁、共享内存方式以及生产者消费者模型
  6. 应用交付:从技术到服务
  7. 智能的定义是什么?如何正确理解智能家居?
  8. 从零开始玩转logback
  9. Redis-stat的安装与使用
  10. nginx 正向代理配置