ziguzagu.org

Ganglia の mysqld python module の MySQL 5.5 対応パッチ

MySQL 5.5 で InnoDB status とれないまま長らく放置していた Ganglia の mysqld python module にパッチあてた。

diff --git a/mysqld/python_modules/DBUtil.py b/mysqld/python_modules/DBUtil.py
index 21b7522..db2bfbb 100644
--- a/mysqld/python_modules/DBUtil.py
+++ b/mysqld/python_modules/DBUtil.py
@@ -86,7 +86,7 @@ def parse_innodb_status(innodb_status_raw):
        innodb_status['active_transactions']

        for line in innodb_status_raw:
-               istatus = line.split()
+               istatus = line.replace(',', '').split()

                isum = sumof(istatus)

@@ -97,15 +97,15 @@ def parse_innodb_status(innodb_status_raw):
                        innodb_status['os_waits'] += longish(istatus[8])

                elif "RW-shared spins" in line:
-                       innodb_status['spin_waits'] += isum(2,8)
-                       innodb_status['os_waits'] += isum(5,11)
+                       innodb_status['spin_waits'] += longish(istatus[2]) # isum(2,8)
+                       innodb_status['os_waits'] += longish(istatus[7]) # isum(5,11)

                # TRANSACTIONS
                elif "Trx id counter" in line:
-                       innodb_status['transactions'] += isum(3,4)
+                       innodb_status['transactions'] += int(istatus[3], 16) # isum(3,4)

                elif "Purge done for trx" in line:
-                       innodb_status['transactions_purged'] += isum(6,7)
+                       innodb_status['transactions_purged'] += int(istatus[6], 16) # isum(6,7)

                elif "History list length" in line:
                        innodb_status['history_list'] = longish(istatus[3])
@@ -155,10 +155,10 @@ def parse_innodb_status(innodb_status_raw):
                        innodb_status['pending_chkp_writes'] = longish(istatus[4])

                elif "Log sequence number" in line:
-                       innodb_status['log_bytes_written'] = isum(3,4)
+                       innodb_status['log_bytes_written'] = longish(istatus[3]) #isum(3,4)

                elif "Log flushed up to" in line:
-                       innodb_status['log_bytes_flushed'] = isum(4,5)
+                       innodb_status['log_bytes_flushed'] = longish(istatus[4]) #isum(4,5)

                # BUFFER POOL AND MEMORY
                elif "Buffer pool size" in line:
@@ -172,6 +172,10 @@ def parse_innodb_status(innodb_status_raw):

                elif "Modified db pages" in line:
                        innodb_status['buffer_pool_pages_dirty'] = longish(istatus[3])
+
+               elif "Pages read ahead" in line:
+                       # XXX: prevent to match next rule by this line
+                       0

                elif "Pages read" in line:
                        innodb_status['pages_read'] = longish(istatus[2])
@@ -209,7 +213,7 @@ if __name__ == '__main__':

                cursor = conn.cursor(MySQLdb.cursors.Cursor)
                cursor.execute("SHOW /*!50000 ENGINE*/ INNODB STATUS")
-               innodb_status = parse_innodb_status(cursor.fetchone()[0].split('\n'))
+               innodb_status = parse_innodb_status(cursor.fetchone()[2].split('\n'))
                cursor.close()

                conn.close()

DBUtil.py には python 2.5 未満でうごかん、みたいなことがほんのり書かれてるけど、Cent OS 5 の標準 python 2.4.3 で残念ながら動いてる(が、EPEL の python26 いれるのがいろいろ良いであろう)。ただ、log_bytes_written、log_bytes_flushed あたりは怪しい数値をだしてるけど…。

というか、だれもつかってないのかしらこのモジュール…。