nagios 監控 mysql 讀寫比 R/W

來源:互聯網
上載者:User

標籤:

#!/usr/bin/python2.7# -*- coding:utf-8 -*-from optparse import OptionParserimport commands,sys,jastme,refrom 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()


nagios 監控 mysql 讀寫比 R/W

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.