nagios 监控 mysql 读写比 R/W
生活随笔
收集整理的這篇文章主要介紹了
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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 挖掘频繁模式、关联和相关
- 下一篇: 利用 Win32 启动和检测 UWP A