Permalink
Browse files

Merge branch 'features/mysql'

  • Loading branch information...
2 parents 2f3e88f + 34742fd commit 148149c6a15c42556eb6317834363ff3a92e9976 @codeinthehole committed Jun 25, 2012
Showing with 451 additions and 1 deletion.
  1. +21 −0 bin/pygmetric_mysql
  2. +113 −0 pygmetric/mysql.py
  3. +1 −1 pygmetric/rabbitmq.py
  4. +1 −0 setup.py
  5. +315 −0 tests/mysql_tests.py
View
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+from optparse import OptionParser
+
+from pygmetric import mysql
+
+if __name__ == '__main__':
+ parser = OptionParser()
+ parser.add_option('--user', dest='user', default='/',
+ help="Specify the user to use")
+ parser.add_option('--password', dest='password',
+ help="Specify the password to use")
+ parser.add_option('-d', '--dry-run', dest='debug', default=False,
+ action='store_true',
+ help="Print out metric commands without submitting")
+ options, args = parser.parse_args()
+ mysql.submit(
+ user=options.user,
+ password=options.password,
+ debug=options.debug,
+ )
View
@@ -0,0 +1,113 @@
+import pygmetric.shell
+import pygmetric
+
+
+def submit(user, password, debug):
+ stats = fetch_stats(user, password)
+ for metric in stats.values():
+ pygmetric.shell.call_gmetric(name=metric['name'],
+ value=metric['value'],
+ type=metric['type'],
+ units=metric['units'],
+ debug=debug)
+
+COUNT_METRICS = {
+ 'Threads_connected': {
+ 'name': 'mysql_threads_connected',
+ 'type': 'uint32',
+ 'units': 'Threads',
+ },
+ 'Threads_running': {
+ 'name': 'mysql_threads_running',
+ 'type': 'uint32',
+ 'units': 'Threads',
+ },
+}
+
+RATE_METRICS = {
+ 'Connections': {
+ 'name': 'mysql_connections_rate',
+ 'type': 'float',
+ 'units': 'Conns/second',
+ },
+ 'Queries': {
+ 'name': 'mysql_query_rate',
+ 'type': 'float',
+ 'units': 'Queries/second',
+ },
+ 'Com_select': {
+ 'name': 'mysql_query_select_rate',
+ 'type': 'float',
+ 'units': 'Queries/second',
+ },
+ 'Com_update': {
+ 'name': 'mysql_query_update_rate',
+ 'type': 'float',
+ 'units': 'Queries/second',
+ },
+ 'Com_insert': {
+ 'name': 'mysql_query_insert',
+ 'type': 'float',
+ 'units': 'Queries/second',
+ },
+ 'Com_delete': {
+ 'name': 'mysql_query_delete_rate',
+ 'type': 'float',
+ 'units': 'Queries/second',
+ },
+ 'Com_load': {
+ 'name': 'mysql_query_load_rate',
+ 'type': 'float',
+ 'units': 'Queries/second',
+ },
+ 'Slow_queries': {
+ 'name': 'mysql_slow_queries',
+ 'type': 'float',
+ 'units': 'Queries/second',
+ },
+ 'Created_tmp_tables': {
+ 'name': 'mysql_created_tmp_tables',
+ 'type': 'float',
+ 'units': 'Tables/second',
+ },
+ 'Bytes_received': {
+ 'name': 'mysql_bytes_received',
+ 'type': 'float',
+ 'units': 'Bytes/second',
+ },
+ 'Bytes_sent': {
+ 'name': 'mysql_bytes_sent',
+ 'type': 'float',
+ 'units': 'Bytes/second',
+ },
+}
+
+
+def fetch_stats(user, password):
+ cmd = 'mysql --user=%s --password=%s -e "SHOW GLOBAL STATUS"' % (user, password)
+ stdout = pygmetric.shell.run(cmd)
+
+ metrics = {}
+ for line in stdout.split("\n"):
+ parts = line.split()
+ if len(parts) != 5:
+ continue
+ mysql_name, value = parts[1], parts[3]
+ if mysql_name in COUNT_METRICS:
+ prototype = COUNT_METRICS[mysql_name]
+ metrics[prototype['name']] = {
+ 'name': prototype['name'],
+ 'value': int(value),
+ 'type': prototype['type'],
+ 'units': prototype['units'],
+ }
+ elif mysql_name in RATE_METRICS:
+ prototype = RATE_METRICS[mysql_name]
+ current_value = int(value)
+ metrics[prototype['name']] = {
+ 'name': prototype['name'],
+ 'value': pygmetric.get_rate(prototype['name'], current_value, 1),
+ 'type': prototype['type'],
+ 'units': prototype['units'],
+ }
+ return metrics
View
@@ -1,5 +1,5 @@
import pygmetric.shell
-import pygmetric
+import pygmetric
def submit(vhost, queue, debug):
View
@@ -12,4 +12,5 @@
scripts=['bin/pygmetric_apache',
'bin/pygmetric_nginx',
'bin/pygmetric_rabbitmq',
+ 'bin/pygmetric_mysql',
])
Oops, something went wrong.

0 comments on commit 148149c

Please sign in to comment.