×

扫描二维码登录本站

标签: mysql监控
来自:网络


[backcolor=rgb(51, 51, 51) !important]9

[backcolor=rgb(51, 51, 51) !important]10

[backcolor=rgb(51, 51, 51) !important]11

[backcolor=rgb(51, 51, 51) !important]12

[backcolor=rgb(51, 51, 51) !important]13

[backcolor=rgb(51, 51, 51) !important]14

[backcolor=rgb(51, 51, 51) !important]15

[backcolor=rgb(51, 51, 51) !important]16

[backcolor=rgb(51, 51, 51) !important]17

[backcolor=rgb(51, 51, 51) !important]18

[backcolor=rgb(51, 51, 51) !important]19

[backcolor=rgb(51, 51, 51) !important]20

[backcolor=rgb(51, 51, 51) !important]21

[backcolor=rgb(51, 51, 51) !important]22

[backcolor=rgb(51, 51, 51) !important]23

[backcolor=rgb(51, 51, 51) !important]24

[backcolor=rgb(51, 51, 51) !important]25

[backcolor=rgb(51, 51, 51) !important]26

[backcolor=rgb(51, 51, 51) !important]27

[backcolor=rgb(51, 51, 51) !important]28

[backcolor=rgb(51, 51, 51) !important]29

[backcolor=rgb(51, 51, 51) !important]30

[backcolor=rgb(51, 51, 51) !important]31

[backcolor=rgb(51, 51, 51) !important]32

[backcolor=rgb(51, 51, 51) !important]33

[backcolor=rgb(51, 51, 51) !important]34

[backcolor=rgb(51, 51, 51) !important]35

[backcolor=rgb(51, 51, 51) !important]36

[backcolor=rgb(51, 51, 51) !important]37

[backcolor=rgb(51, 51, 51) !important]38

[backcolor=rgb(51, 51, 51) !important]39

[backcolor=rgb(51, 51, 51) !important]40

[backcolor=rgb(51, 51, 51) !important]41

[backcolor=rgb(51, 51, 51) !important]42

[backcolor=rgb(51, 51, 51) !important]43

[backcolor=rgb(51, 51, 51) !important]44

[backcolor=rgb(51, 51, 51) !important]45

[backcolor=rgb(51, 51, 51) !important]46

[backcolor=rgb(51, 51, 51) !important]47

[backcolor=rgb(51, 51, 51) !important]48

[backcolor=rgb(51, 51, 51) !important]49

[backcolor=rgb(51, 51, 51) !important]50

[backcolor=rgb(51, 51, 51) !important]51

[backcolor=rgb(51, 51, 51) !important]52

[backcolor=rgb(51, 51, 51) !important]53

[backcolor=rgb(51, 51, 51) !important]54

[backcolor=rgb(51, 51, 51) !important]55

[backcolor=rgb(51, 51, 51) !important]56

[backcolor=rgb(51, 51, 51) !important]57

[backcolor=rgb(51, 51, 51) !important]58

[backcolor=rgb(51, 51, 51) !important]59

[backcolor=rgb(51, 51, 51) !important]60

[backcolor=rgb(51, 51, 51) !important]61

[backcolor=rgb(51, 51, 51) !important]62

[backcolor=rgb(51, 51, 51) !important]63

[backcolor=rgb(51, 51, 51) !important]64

[backcolor=rgb(51, 51, 51) !important]65

[backcolor=rgb(51, 51, 51) !important]66

[backcolor=rgb(51, 51, 51) !important]67

[backcolor=rgb(51, 51, 51) !important]68

[backcolor=rgb(51, 51, 51) !important]69

[backcolor=rgb(51, 51, 51) !important]70

[backcolor=rgb(51, 51, 51) !important]71

[backcolor=rgb(51, 51, 51) !important]72

[backcolor=rgb(51, 51, 51) !important]73

[backcolor=rgb(51, 51, 51) !important]74

[backcolor=rgb(51, 51, 51) !important]75

[backcolor=rgb(51, 51, 51) !important]76

[backcolor=rgb(51, 51, 51) !important]77

[backcolor=rgb(51, 51, 51) !important]78

[backcolor=rgb(51, 51, 51) !important]79

[backcolor=rgb(51, 51, 51) !important]80

[backcolor=rgb(51, 51, 51) !important]81

[backcolor=rgb(51, 51, 51) !important]82

[backcolor=rgb(51, 51, 51) !important]83

[backcolor=rgb(51, 51, 51) !important]84

[backcolor=rgb(51, 51, 51) !important]85

[backcolor=rgb(51, 51, 51) !important]86

[backcolor=rgb(51, 51, 51) !important]87

[backcolor=rgb(51, 51, 51) !important]88

[backcolor=rgb(51, 51, 51) !important]89

[backcolor=rgb(51, 51, 51) !important]90

[backcolor=rgb(51, 51, 51) !important]91

[backcolor=rgb(51, 51, 51) !important]92

[backcolor=rgb(51, 51, 51) !important]93

[backcolor=rgb(51, 51, 51) !important]94

[backcolor=rgb(51, 51, 51) !important]95

[backcolor=rgb(51, 51, 51) !important]96

[backcolor=rgb(51, 51, 51) !important]97

[backcolor=rgb(51, 51, 51) !important]98

[backcolor=rgb(51, 51, 51) !important]99

[backcolor=rgb(51, 51, 51) !important]100

[backcolor=rgb(51, 51, 51) !important]101

[backcolor=rgb(51, 51, 51) !important]102

[backcolor=rgb(51, 51, 51) !important]103

[backcolor=rgb(51, 51, 51) !important]104

[backcolor=rgb(51, 51, 51) !important]105

[backcolor=rgb(51, 51, 51) !important]106

[backcolor=rgb(51, 51, 51) !important]107

[backcolor=rgb(51, 51, 51) !important]108

[backcolor=rgb(51, 51, 51) !important]109

[backcolor=rgb(51, 51, 51) !important]110

[backcolor=rgb(51, 51, 51) !important]111

[backcolor=rgb(51, 51, 51) !important]112

[backcolor=rgb(51, 51, 51) !important]113

[backcolor=rgb(51, 51, 51) !important]114

[backcolor=rgb(51, 51, 51) !important]115

[backcolor=rgb(51, 51, 51) !important]116

[backcolor=rgb(51, 51, 51) !important]117

[backcolor=rgb(51, 51, 51) !important]118

[backcolor=rgb(51, 51, 51) !important]119

[backcolor=rgb(51, 51, 51) !important]120

[backcolor=rgb(51, 51, 51) !important]121

[backcolor=rgb(51, 51, 51) !important]#!/usr/bin/python2.7                               nagios安装

[backcolor=rgb(51, 51, 51) !important]# -*- coding:utf-8 -*-

[backcolor=rgb(51, 51, 51) !important]from __future__ import division

[backcolor=rgb(51, 51, 51) !important]from optparse import OptionParser

[backcolor=rgb(51, 51, 51) !important]import commands,sys,jastme,re

[backcolor=rgb(51, 51, 51) !important]from datetime import datetime

[backcolor=rgb(51, 51, 51) !important]"""

[backcolor=rgb(51, 51, 51) !important]    Nagios plugin to report the mysql TPS                   开源监控软件

[backcolor=rgb(51, 51, 51) !important]    author jastme

[backcolor=rgb(51, 51, 51) !important]"""


[backcolor=rgb(51, 51, 51) !important]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 ")

[backcolor=rgb(51, 51, 51) !important]         

[backcolor=rgb(51, 51, 51) !important]parser.add_option("-w", "--warning",action="store", type="string", dest="warn_threshold", help="Warning threshold in percentage")

[backcolor=rgb(51, 51, 51) !important]         

[backcolor=rgb(51, 51, 51) !important]parser.add_option("-c", "--critical",action="store", type="string", dest="crit_threshold", help="Critical threshold in percentage")

[backcolor=rgb(51, 51, 51) !important]                         nagios配置

[backcolor=rgb(51, 51, 51) !important](options, args) = parser.parse_args()


[backcolor=rgb(51, 51, 51) !important]try:

[backcolor=rgb(51, 51, 51) !important]    f=open('/tmp/Com_commit.txt')

[backcolor=rgb(51, 51, 51) !important]except IOError:

[backcolor=rgb(51, 51, 51) !important]    f=open('/tmp/Com_commit.txt','w')

[backcolor=rgb(51, 51, 51) !important]    print 'wait next check,initialize the date time.txt'

[backcolor=rgb(51, 51, 51) !important]finally:   

[backcolor=rgb(51, 51, 51) !important]    f.close()


[backcolor=rgb(51, 51, 51) !important]try:

[backcolor=rgb(51, 51, 51) !important]    f=open('/tmp/Com_rollback.txt')

[backcolor=rgb(51, 51, 51) !important]except IOError:

[backcolor=rgb(51, 51, 51) !important]    f=open('/tmp/Com_rollback.txt','w')

[backcolor=rgb(51, 51, 51) !important]    print 'wait next check,initialize the date time.txt'                        监控软件

[backcolor=rgb(51, 51, 51) !important]finally:   

[backcolor=rgb(51, 51, 51) !important]    f.close()


[backcolor=rgb(51, 51, 51) !important]try:

[backcolor=rgb(51, 51, 51) !important]    f=open('/tmp/tpstime.txt')

[backcolor=rgb(51, 51, 51) !important]except IOError:

[backcolor=rgb(51, 51, 51) !important]    f=open('/tmp/tpstime.txt','w')

[backcolor=rgb(51, 51, 51) !important]    print 'wait next check,initialize the date time.txt'

[backcolor=rgb(51, 51, 51) !important]finally:   

[backcolor=rgb(51, 51, 51) !important]    f.close()


[backcolor=rgb(51, 51, 51) !important]class Monitor:


[backcolor=rgb(51, 51, 51) !important]    def __init__(self,username,password,hostname,port):

[backcolor=rgb(51, 51, 51) !important]        """ you can call sam var here """

[backcolor=rgb(51, 51, 51) !important]        self.username = username

[backcolor=rgb(51, 51, 51) !important]        self.password = password                   nagios实施

[backcolor=rgb(51, 51, 51) !important]        self.port = port

[backcolor=rgb(51, 51, 51) !important]        self.hostname = hostname


[backcolor=rgb(51, 51, 51) !important]    def __Com_commit(self):


[backcolor=rgb(51, 51, 51) !important]        now=commands.getoutput(''' mysql -u%s -p%s -h%s -P%s -e "show global status like 'Com_commit'" | grep -Po "\d+"  ''' %(self.username,self.password,self.hostname,self.port))

[backcolor=rgb(51, 51, 51) !important]        now=re.findall(r'\d+',now)[0]

[backcolor=rgb(51, 51, 51) !important]        f=open('/tmp/Com_commit.txt','r')

[backcolor=rgb(51, 51, 51) !important]        before=f.readlines()

[backcolor=rgb(51, 51, 51) !important]        f.close()

[backcolor=rgb(51, 51, 51) !important]        if before == []:

[backcolor=rgb(51, 51, 51) !important]            ff=open('/tmp/Com_commit.txt','w')

[backcolor=rgb(51, 51, 51) !important]            ff.write(now)

[backcolor=rgb(51, 51, 51) !important]            ff.close()

[backcolor=rgb(51, 51, 51) !important]        else:

[backcolor=rgb(51, 51, 51) !important]            before=before[-1]

[backcolor=rgb(51, 51, 51) !important]            N = int(now)-int(before)

[backcolor=rgb(51, 51, 51) !important]            ff=open('/tmp/Com_commit.txt','w')

[backcolor=rgb(51, 51, 51) !important]            ff.write(now)

[backcolor=rgb(51, 51, 51) !important]            ff.close()

[backcolor=rgb(51, 51, 51) !important]            return N


[backcolor=rgb(51, 51, 51) !important]    def __Com_rollback(self):


[backcolor=rgb(51, 51, 51) !important]        now=commands.getoutput(''' mysql -u%s -p%s -h%s -P%s -e "show global status like 'Com_rollback'" | grep -Po "\d+" '''  %(self.username,self.password,self.hostname,self.port))

[backcolor=rgb(51, 51, 51) !important]        now=re.findall(r'\d+',now)[0]                  nagios培训

[backcolor=rgb(51, 51, 51) !important]        f=open('/tmp/Com_rollback.txt','r')

[backcolor=rgb(51, 51, 51) !important]        before=f.readlines()

[backcolor=rgb(51, 51, 51) !important]        f.close()

[backcolor=rgb(51, 51, 51) !important]        if before == []:

[backcolor=rgb(51, 51, 51) !important]            ff=open('/tmp/Com_rollback.txt','w')

[backcolor=rgb(51, 51, 51) !important]            ff.write(now)

[backcolor=rgb(51, 51, 51) !important]            ff.close()

[backcolor=rgb(51, 51, 51) !important]        else:

[backcolor=rgb(51, 51, 51) !important]            before=before[-1]

[backcolor=rgb(51, 51, 51) !important]            ff=open('/tmp/Com_rollback.txt','w')

[backcolor=rgb(51, 51, 51) !important]            ff.write(now)

[backcolor=rgb(51, 51, 51) !important]            ff.close()

[backcolor=rgb(51, 51, 51) !important]            N = int(now)-int(before)

[backcolor=rgb(51, 51, 51) !important]            return N


[backcolor=rgb(51, 51, 51) !important]    def __Uptime(self):

[backcolor=rgb(51, 51, 51) !important]        time_now=datetime.now()

[backcolor=rgb(51, 51, 51) !important]        ff=open('/tmp/tpstime.txt','r')

[backcolor=rgb(51, 51, 51) !important]        time_before_str=ff.read()

[backcolor=rgb(51, 51, 51) !important]        ff.close()

[backcolor=rgb(51, 51, 51) !important]        if time_before_str=='':

[backcolor=rgb(51, 51, 51) !important]            ffw=open('/tmp/tpstime.txt','w')

[backcolor=rgb(51, 51, 51) !important]            ffw.write(str(time_now))

[backcolor=rgb(51, 51, 51) !important]            ffw.close()

[backcolor=rgb(51, 51, 51) !important]        else:

[backcolor=rgb(51, 51, 51) !important]            time_before=datetime.strptime(time_before_str,"%Y-%m-%d %H:%M:%S.%f")

[backcolor=rgb(51, 51, 51) !important]            delay=(time_now-time_before).seconds

[backcolor=rgb(51, 51, 51) !important]            ffw=open('/tmp/tpstime.txt','w')

[backcolor=rgb(51, 51, 51) !important]            ffw.write(str(time_now))

[backcolor=rgb(51, 51, 51) !important]            ffw.close()

[backcolor=rgb(51, 51, 51) !important]            return delay



[backcolor=rgb(51, 51, 51) !important]    def doit(self):

[backcolor=rgb(51, 51, 51) !important]        _Com_commit = int(self.__Com_commit())

[backcolor=rgb(51, 51, 51) !important]        _Com_rollback = int(self.__Com_rollback())

[backcolor=rgb(51, 51, 51) !important]        _Uptime = int(self.__Uptime())

[backcolor=rgb(51, 51, 51) !important]        R = ( _Com_rollback + _Com_commit) / _Uptime

[backcolor=rgb(51, 51, 51) !important]        print "TPS is %.1f | TPS=%.1f" %(R,R)


[backcolor=rgb(51, 51, 51) !important]if __name__ == "__main__":

[backcolor=rgb(51, 51, 51) !important]    username = "monitor"

[backcolor=rgb(51, 51, 51) !important]    password = str(jastme.decrypt(119,u'NALBOBJBCBHAGBOA'))

[backcolor=rgb(51, 51, 51) !important]    hostname = "127.0.0.1"

[backcolor=rgb(51, 51, 51) !important]    port = "3369"

[backcolor=rgb(51, 51, 51) !important]    Monitor(username,password,hostname,port).doit()






想做Nagios Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流  QQ群号 476809427





上一篇:nagios监控mysql tps
下一篇:用什么自动推送nagios client脚本
monicazhang

写了 2297 篇文章,拥有财富 12859,被 21 人关注

您需要登录后才可以回帖 登录 | 立即注册
B Color Link Quote Code Smilies

成为第一个吐槽的人

Powered by ITIL  © 2001-2025
返回顶部