nagios 监控 mysql 读写比 R/W

#!/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 Ratio
    author jastme
"""

parser = OptionParser(usage="%prog -w <warning threshold> -c <critical threshold> [ -h ]\n\nBefore use the script,please execute ‘grant usage on *.* to [email protected]‘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 = username
        self.password = password
        self.port = port
        self.hostname = hostname

    def __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 R

    def __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 R

    def __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 R

    def __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 R

    def __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 R

    def __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 R

    def __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 ) * 100
        return R

    def 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()
时间: 2024-08-04 08:08:28

nagios 监控 mysql 读写比 R/W的相关文章

Nagios监控MySQL报错:NRPE: Unable to read output的详细解决过程

前言:nagios界面上,看到监控mysql服务报错如下: Warning:NRPE: Unable to read output 1,去nagios监控服务器上check下 1.1,执行check_nrpe命令远程调用 在监控端nagios服务器上执行check_nrpe检查mysql状态报错如下: [[email protected] ~]# /usr/lib/nagios/plugins/check_nrpe  -H192.xx.180.xx -c check_mysql_status N

Nagios 监控mysql服务器详细实现过程

1.NRPE介绍 NRPE是Nagios的一个功能扩展,它可在远程Linux/Unix主机上执行插件程序.通过在远程服务器上安装NRPE插件及Nagios插件程序来向Nagios监控平台提供该服务器的本地情况,如CPU负载,内存使用,磁盘使用等.这里将Nagios监控端称为Nagios服务器端,而将远程被监控的主机称为Nagios客户端. Nagios监控远程主机的方法有多种,其方式包括SNMP,NRPE,SSH,NCSA等.这里介绍其通过NRPE监控远程Linux主机的方式. NRPE(Nag

nagios监控mysql

在nagios上部署check_mysql_health 监控mysql 博客分类: 架构 本监控为基于nagios服务器主动监控方法,利用check_mysql_health实现多种监控模式:       connection-time          (Time to connect to the server)       uptime                   (Time the server is running)       threads-connected      

zabbix监控mysql-如何使用zabbix自带的模板监控-nagios监控mysql主从

用zabbix监控mysql(源码安装)安装位置在/usr/local/zabbix/ 监控端(server): 在被监控端主机上关联该模板Template App MySQL 中文:组态->主机->名称一栏点击进去->模板,点击链接新模板->添加->Template App MySQL->存档 英文:Configuration->Hosts->Name->Templates,Link new templates->Add->Templat

nagios监控mysql tps---check_mysql_tps.py

#!/usr/bin/python2.7 # -*- coding:utf-8 -*- from __future__ import division from optparse import OptionParser import commands,sys,jastme,re from datetime import datetime """     Nagios plugin to report the mysql TPS     author jastme "

nagios监控mysql主从,并且邮件告警!

客户端操作: yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe#安装 vim /etc/nagios/nrpe.cfg    #更改客户端的nrpe配置文件 allowed_hosts=192.168.20.168    #IP更改成监控端的地址,如果是多个使用,分割开 #漏了这个后期会出现CHECK_NRPE: Error - Could not complete SSL handshake. 的

Nagios监控Mysql数据库

实验拓扑:地址分配:Nagios 192.168.1.1Mysql 192.168.1.2Nagios上的操作:1)安装nagios#make install //安装主程序,CGI和HTML文件 make install-init //在/etc/rc.d/init.d安装启动脚本 make install-commandmode //配置目录权限 make install-config //安装示例配置文件 make install-webconf //安装nagios的web接口,会在/e

Nagios 监控 Mysql

被监控机的Mysql监控创建专用数据库.专用数据库账户mysql -uroot -pcreate database nagios_monitor;grant select on nagios_monitor.* to [email protected]'%' identified by 'nagiosMonitor';flush privileges;exit;测试check_mysql脚本运行是否正常cd /usr/lib64/nagios/plugins./check_mysql -unag

第25章 MySQL replication(主从)配置及加入nagios监控

环境介绍: master:23.247.76.253 [[email protected]_client1 tool]# mysql -V mysql  Ver 14.14 Distrib 5.6.32, for linux-glibc2.5 (x86_64) using  EditLine wrapper [[email protected]_client1 tool]# cat /etc/redhat-release CentOS release 6.7 (Final) slave:23.2