Skip to content

Commit 0faa64e

Browse files
ArtArt
authored andcommitted
Syncing with the original project
1 parent cb77f10 commit 0faa64e

File tree

7 files changed

+198
-12
lines changed

7 files changed

+198
-12
lines changed

README.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ Usage
5858
-h, --help show this help message and exit
5959
-c FILE, --config FILE
6060
Configuration file
61-
-d, --debug Debug mode
61+
-d, --debug Prints statsd metrics next to sending them
62+
--dry-run Print the output that would be sent to statsd without
63+
actually sending data somewhere
6264
-f, --foreground Dont fork main program
6365

6466
At the moment there is also a `deamon
@@ -236,11 +238,12 @@ https://www.percona.com/live/europe-amsterdam-2015/sessions/mysql-performance-mo
236238
Contributors
237239
------------
238240

239-
~~spil-jasper~~
241+
spil-jasper **no longer works on the project**
240242

241-
~~thijsdezoete~~
243+
thijsdezoete **no longer works on the project**
242244

243-
~~art-spilgames~~
245+
art-spilgames **now known as banpei-dbart**
244246

245247
banpei-dbart
246248

249+
bnkr

mysql_statsd/mysql_statsd.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from thread_manager import ThreadManager
1414
from thread_mysql import ThreadMySQL
15-
from thread_statsd import ThreadStatsd
15+
from thread_statsd import ThreadStatsd, ThreadFakeStatsd
1616

1717

1818
class MysqlStatsd():
@@ -23,8 +23,19 @@ class MysqlStatsd():
2323
def __init__(self):
2424
"""Program entry point"""
2525
op = argparse.ArgumentParser()
26-
op.add_argument("-c", "--config", dest="cfile", default="/etc/mysql-statsd.conf", help="Configuration file")
27-
op.add_argument("-d", "--debug", dest="debug", help="Debug mode", default=False, action="store_true")
26+
op.add_argument("-c", "--config", dest="cfile",
27+
default="/etc/mysql-statsd.conf",
28+
help="Configuration file"
29+
)
30+
op.add_argument("-d", "--debug", dest="debug",
31+
help="Prints statsd metrics next to sending them",
32+
default=False, action="store_true"
33+
)
34+
op.add_argument("--dry-run", dest="dry_run",
35+
default=False,
36+
action="store_true",
37+
help="Print the output that would be sent to statsd without actually sending data somewhere"
38+
)
2839

2940
# TODO switch the default to True, and make it fork by default in init script.
3041
op.add_argument("-f", "--foreground", dest="foreground", help="Dont fork main program", default=False, action="store_true")
@@ -60,6 +71,13 @@ def __init__(self):
6071
# Spawn Statsd flushing thread
6172
statsd_thread = ThreadStatsd(queue=self.queue, **statsd_config)
6273

74+
if opt.dry_run:
75+
statsd_thread = ThreadFakeStatsd(queue=self.queue, **statsd_config)
76+
77+
if opt.debug:
78+
""" All debug settings go here """
79+
statsd_thread.debug = True
80+
6381
# Get thread manager
6482
tm = ThreadManager(threads=[mysql_thread, statsd_thread])
6583
tm.run()

mysql_statsd/preprocessors/innodb_preprocessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def process(self, rows):
6767

6868
# Process the individual buffer pool
6969
bufferpool = 'bufferpool_0.'
70-
for line in chunks['INDIVIDUAL BUFFER POOL INFO']:
70+
for line in chunks.get('INDIVIDUAL BUFFER POOL INFO', []):
7171
# Buffer pool stats are preceded by:
7272
# ---BUFFER POOL X
7373
if line.startswith('---'):

mysql_statsd/thread_statsd.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def run(self):
2525

2626

2727
class ThreadStatsd(ThreadBase):
28+
debug = False
29+
2830
def configure(self, config):
2931
host = config.get('host', 'localhost')
3032
port = int(config.get('port', 8125))
@@ -73,11 +75,19 @@ def run(self):
7375
try:
7476
# Timeout after 1 second so we can respond to quit events
7577
item = self.queue.get(True, 1)
78+
if self.debug:
79+
print(item)
7680
self.send_stat(item)
7781
except Queue.Empty:
7882
continue
7983

8084

85+
class ThreadFakeStatsd(ThreadStatsd):
86+
"""Prints metrics instead of sending them to statsd."""
87+
def send_stat(self, item):
88+
print item
89+
90+
8191
if __name__ == '__main__':
8292
# Run standalone to test this module, it will generate garbage
8393
from thread_manager import ThreadManager

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
setup(
2121
name='mysql-statsd',
22-
version='0.1.2',
22+
version='0.1.4',
2323
description='Daemon that gathers statistics from MySQL and sends them to statsd.',
2424
long_description=readme + '\n\n' + history,
25-
author='Jasper Capel, Thijs de Zoete',
26-
author_email='jasper.capel@spilgames.com',
27-
url='https://github.com/spilgames/mysql_statsd',
25+
author='Art van Scheppingen',
26+
author_email='art@dbart.net',
27+
url='https://github.com/db-art/mysql-statsd',
2828
packages=[
2929
'mysql_statsd',
3030
],

tests/__init__.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
import unittest
4+
import os
5+
from mysql_statsd.preprocessors import InnoDBPreprocessor
6+
7+
class InnoDBPreprocessorTest(unittest.TestCase):
8+
def test_values_read_from_vanilla_install(self):
9+
"""
10+
For this mysqld version in default setup::
11+
12+
$ /usr/sbin/mysqld --version
13+
/usr/sbin/mysqld Ver 5.5.41-0+wheezy1 for debian-linux-gnu on x86_64 ((Debian))
14+
15+
A basic coverage test.
16+
"""
17+
fixture = os.path.join(os.path.dirname(__file__), 'fixtures',
18+
'show-innodb-status-5.5-vanilla')
19+
row = open(fixture, 'rb').read()
20+
21+
processor = InnoDBPreprocessor()
22+
processed = processor.process([('InnoDB', '', row)])
23+
expected = {
24+
'additional_pool_alloc': '0',
25+
'current_transactions': 1,
26+
'database_pages': '142',
27+
'empty': '',
28+
'free_pages': '8049',
29+
'hash_index_cells_total': '276671',
30+
'hash_index_cells_used': 0,
31+
'history_list': '0',
32+
'ibuf_cell_count': '2',
33+
'ibuf_free_cells': '0',
34+
'ibuf_merges': '0',
35+
'ibuf_used_cells': '1',
36+
'innodb_transactions': 1282,
37+
'last_checkpoint': '1595685',
38+
'log_bytes_flushed': '1595685',
39+
'log_bytes_written': '1595685',
40+
'modified_pages': '0',
41+
'os_waits': '0',
42+
'pages_created': '0',
43+
'pages_read': '142',
44+
'pages_written': '1',
45+
'pending_buf_pool_flushes': '0',
46+
'pending_log_flushes': '0',
47+
'pending_normal_aio_reads': '0',
48+
'pending_normal_aio_writes': '0',
49+
'pool_size': '8191',
50+
'read_views': '1',
51+
'rows_deleted': '0',
52+
'rows_inserted': '0',
53+
'rows_read': '0',
54+
'rows_updated': '0',
55+
'spin_rounds': '0',
56+
'spin_waits': '0',
57+
'total_mem_alloc': '137363456',
58+
'unpurged_txns': 1282, }
59+
self.assertEquals(expected, dict(processed))
60+
61+
if __name__ == "__main__":
62+
unittest.main()
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
=====================================
2+
150221 12:34:19 INNODB MONITOR OUTPUT
3+
=====================================
4+
Per second averages calculated from the last 16 seconds
5+
-----------------
6+
BACKGROUND THREAD
7+
-----------------
8+
srv_master_thread loops: 2 1_second, 2 sleeps, 0 10_second, 3 background, 3 flush
9+
srv_master_thread log flush and writes: 3
10+
----------
11+
SEMAPHORES
12+
----------
13+
OS WAIT ARRAY INFO: reservation count 3, signal count 3
14+
Mutex spin waits 0, rounds 0, OS waits 0
15+
RW-shared spins 3, rounds 90, OS waits 3
16+
RW-excl spins 0, rounds 0, OS waits 0
17+
Spin rounds per wait: 0.00 mutex, 30.00 RW-shared, 0.00 RW-excl
18+
------------
19+
TRANSACTIONS
20+
------------
21+
Trx id counter 502
22+
Purge done for trx's n:o < 0 undo n:o < 0
23+
History list length 0
24+
LIST OF TRANSACTIONS FOR EACH SESSION:
25+
---TRANSACTION 0, not started
26+
MySQL thread id 48, OS thread handle 0x7fc0ebabd700, query id 694 localhost root
27+
show engine innodb status
28+
--------
29+
FILE I/O
30+
--------
31+
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
32+
I/O thread 1 state: waiting for completed aio requests (log thread)
33+
I/O thread 2 state: waiting for completed aio requests (read thread)
34+
I/O thread 3 state: waiting for completed aio requests (read thread)
35+
I/O thread 4 state: waiting for completed aio requests (read thread)
36+
I/O thread 5 state: waiting for completed aio requests (read thread)
37+
I/O thread 6 state: waiting for completed aio requests (write thread)
38+
I/O thread 7 state: waiting for completed aio requests (write thread)
39+
I/O thread 8 state: waiting for completed aio requests (write thread)
40+
I/O thread 9 state: waiting for completed aio requests (write thread)
41+
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
42+
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
43+
Pending flushes (fsync) log: 0; buffer pool: 0
44+
153 OS file reads, 7 OS file writes, 7 OS fsyncs
45+
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
46+
-------------------------------------
47+
INSERT BUFFER AND ADAPTIVE HASH INDEX
48+
-------------------------------------
49+
Ibuf: size 1, free list len 0, seg size 2, 0 merges
50+
merged operations:
51+
insert 0, delete mark 0, delete 0
52+
discarded operations:
53+
insert 0, delete mark 0, delete 0
54+
Hash table size 276671, node heap has 0 buffer(s)
55+
0.00 hash searches/s, 0.00 non-hash searches/s
56+
---
57+
LOG
58+
---
59+
Log sequence number 1595685
60+
Log flushed up to 1595685
61+
Last checkpoint at 1595685
62+
0 pending log writes, 0 pending chkp writes
63+
10 log i/o's done, 0.00 log i/o's/second
64+
----------------------
65+
BUFFER POOL AND MEMORY
66+
----------------------
67+
Total memory allocated 137363456; in additional pool allocated 0
68+
Dictionary memory allocated 33650
69+
Buffer pool size 8191
70+
Free buffers 8049
71+
Database pages 142
72+
Old database pages 0
73+
Modified db pages 0
74+
Pending reads 0
75+
Pending writes: LRU 0, flush list 0, single page 0
76+
Pages made young 0, not young 0
77+
0.00 youngs/s, 0.00 non-youngs/s
78+
Pages read 142, created 0, written 1
79+
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
80+
No buffer pool page gets since the last printout
81+
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
82+
LRU len: 142, unzip_LRU len: 0
83+
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
84+
--------------
85+
ROW OPERATIONS
86+
--------------
87+
0 queries inside InnoDB, 0 queries in queue
88+
1 read views open inside InnoDB
89+
Main thread process no. 8651, id 140466251474688, state: waiting for server activity
90+
Number of rows inserted 0, updated 0, deleted 0, read 0
91+
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
92+
----------------------------
93+
END OF INNODB MONITOR OUTPUT
94+
============================
95+

0 commit comments

Comments
 (0)