forked from zhishutech/mysqldba
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YeJinrong
committed
Mar 3, 2019
1 parent
dda8cb9
commit 8909ea8
Showing
3 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2019/2/15 14:02 | ||
# @Author : xucl | ||
# @Email : [email protected] | ||
# @howtouse: dstat --innodb-checkpoint | ||
global mysql_options | ||
mysql_options = os.getenv('DSTAT_MYSQL') | ||
|
||
class dstat_plugin(dstat): | ||
def __init__(self): | ||
self.name = 'innodb checkpoint lags' | ||
self.nick = ('LSN1', 'LSN4', 'LAG') | ||
self.vars = ('lsn_now', 'lsn_check', 'lsn_lag') | ||
self.type = 'd' | ||
self.width = 20 | ||
self.scale = 1000 | ||
|
||
def check(self): | ||
if os.access('/usr/bin/mysql', os.X_OK): | ||
try: | ||
self.stdin, self.stdout, self.stderr = dpopen('/usr/bin/mysql -n %s' % mysql_options) | ||
except IOError: | ||
raise Exception, 'Cannot interface with MySQL binary' | ||
return True | ||
raise Exception, 'Needs MySQL binary' | ||
|
||
def extract(self): | ||
try: | ||
self.stdin.write('show engine innodb status\G\n') | ||
line1 = greppipe(self.stdout, 'Log sequence number') | ||
line2 = greppipe(self.stdout, 'Last checkpoint at') | ||
|
||
if line1: | ||
l1 = line1.split() | ||
self.set2['lsn_now'] = int(l1[3].rstrip(' ')) | ||
if line2: | ||
l2 = line2.split() | ||
self.set2['lsn_check'] = int(l2[3].rstrip(' ')) | ||
self.set2['lsn_lag'] = int(int(l1[3].rstrip(' ')) - int(l2[3].rstrip(' '))) | ||
#for name in self.vars: | ||
# self.val[name] = (self.set2[name] - self.set1[name]) * 1.0 / elapsed | ||
self.val['lsn_now'] = (self.set2['lsn_now']) | ||
self.val['lsn_check'] = (self.set2['lsn_check']) | ||
self.val['lsn_lag'] = (self.set2['lsn_lag']) | ||
|
||
except IOError, e: | ||
if op.debug > 1: print '%s: lost pipe to mysql, %s' % (self.filename, e) | ||
for name in self.vars: self.val[name] = -1 | ||
|
||
except Exception, e: | ||
if op.debug > 1: print '%s: exception' % (self.filename, e) | ||
for name in self.vars: self.val[name] = -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2019/2/15 14:02 | ||
# @Author : xucl | ||
# @Email : [email protected] | ||
# @howtouse: dstat --innodb-list | ||
global mysql_options | ||
mysql_options = os.getenv('DSTAT_MYSQL') | ||
|
||
class dstat_plugin(dstat): | ||
def __init__(self): | ||
self.name = 'innodb list length' | ||
self.nick = ('unpurged', 'free') | ||
self.vars = ('u_list', 'f_list') | ||
self.type = 'd' | ||
self.width = 10 | ||
self.scale = 1000 | ||
|
||
def check(self): | ||
if os.access('/usr/bin/mysql', os.X_OK): | ||
try: | ||
self.stdin, self.stdout, self.stderr = dpopen('/usr/bin/mysql -n %s' % mysql_options) | ||
except IOError: | ||
raise Exception, 'Cannot interface with MySQL binary' | ||
return True | ||
raise Exception, 'Needs MySQL binary' | ||
|
||
def extract(self): | ||
try: | ||
self.stdin.write('show engine innodb status\G\n') | ||
line1 = greppipe(self.stdout, 'History list length') | ||
line2 = greppipe(self.stdout, 'free list len') | ||
|
||
if line1: | ||
l1 = line1.split() | ||
self.set2['u_list'] = int(l1[3].rstrip(' ')) | ||
if line2: | ||
l2 = line2.split() | ||
self.set2['f_list'] = int((l2[6]).rstrip(',')) | ||
|
||
#for name in self.vars: | ||
# self.val[name] = (self.set2[name] - self.set1[name]) * 1.0 / elapsed | ||
self.val['u_list'] = (self.set2['u_list']) | ||
self.val['f_list'] = (self.set2['f_list']) | ||
|
||
except IOError, e: | ||
if op.debug > 1: print '%s: lost pipe to mysql, %s' % (self.filename, e) | ||
for name in self.vars: self.val[name] = -1 | ||
|
||
except Exception, e: | ||
if op.debug > 1: print '%s: exception' % (self.filename, e) | ||
for name in self.vars: self.val[name] = -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2019/2/15 14:02 | ||
# @Author : xucl | ||
# @Email : [email protected] | ||
# @howtouse: dstat --mysql5-rowlockwaits | ||
global mysql_user | ||
mysql_user = os.getenv('DSTAT_MYSQL_USER') or os.getenv('USER') | ||
|
||
global mysql_pwd | ||
mysql_pwd = os.getenv('DSTAT_MYSQL_PWD') | ||
|
||
global mysql_host | ||
mysql_host = os.getenv('DSTAT_MYSQL_HOST') | ||
|
||
global mysql_port | ||
mysql_port = os.getenv('DSTAT_MYSQL_PORT') | ||
|
||
class dstat_plugin(dstat): | ||
""" | ||
Plugin for MySQL 5 connections. | ||
""" | ||
|
||
def __init__(self): | ||
self.name = 'innodb lock waits' | ||
self.nick = ('current_waits', 'total_waits') | ||
self.vars = ('current_waits', 'waits') | ||
self.type = 'd' | ||
self.width = 15 | ||
self.scale = 1 | ||
|
||
def check(self): | ||
global MySQLdb | ||
import MySQLdb | ||
try: | ||
self.db = MySQLdb.connect(user=mysql_user, passwd=mysql_pwd, host=mysql_host, port=int(mysql_port)) | ||
except Exception, e: | ||
raise Exception, 'Cannot interface with MySQL server, %s' % e | ||
|
||
def extract(self): | ||
try: | ||
c = self.db.cursor() | ||
c.execute("""show global status like 'Innodb_row_lock_current_waits';""") | ||
current_waits = c.fetchone() | ||
c.execute("""show global status like 'Innodb_row_lock_waits';""") | ||
waits = c.fetchone() | ||
if current_waits: | ||
self.set2['current_waits'] = int(current_waits[1]) | ||
if waits: | ||
self.set2['waits'] = int(waits[1]) | ||
#for name in self.vars: | ||
# self.val[name] = self.set2[name] * 1.0 / elapsed | ||
self.val['current_waits'] = self.set2['current_waits'] | ||
self.val['waits'] = self.set2['waits'] | ||
if step == op.delay: | ||
self.set1.update(self.set2) | ||
|
||
except Exception, e: | ||
for name in self.vars: | ||
self.val[name] = -1 | ||
|
||
# vim:ts=4:sw=4:et |