Skip to content

Instantly share code, notes, and snippets.

@smalleni
Last active August 30, 2017 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smalleni/8da8c75f1765c23d7706706126dd4c2d to your computer and use it in GitHub Desktop.
Save smalleni/8da8c75f1765c23d7706706126dd4c2d to your computer and use it in GitHub Desktop.
odl-journal
import pymysql
import operator
import sys
# Edit these values:
HOST='172.16.0.13'
USER='mysql'
PASS='mysql'
TOP_N = 5
db = pymysql.connect(host=HOST, user=USER, password=PASS, db='ovs_neutron')
cursor = db.cursor(pymysql.cursors.DictCursor)
cursor.execute('SELECT object_type, object_uuid, operation, state, retry_count, created_at, last_retried FROM opendaylightjournal WHERE state="failed"')
failed_entries = cursor.fetchall()
if failed_entries:
print('WARNING: Failed entries found in the journal :-(')
# TODO(lucasagomes): Show entries
def profile(op=None, top_number=TOP_N):
if op is None:
op = ''
else:
op = 'AND operation="%s"' % op
sql = 'SELECT COUNT(*) count FROM opendaylightjournal WHERE state="completed" %s' % op
cursor.execute(sql)
count = cursor.fetchone()['count']
print(' Number of operations: %d' % count)
if count <= 0:
return
sql = 'SELECT AVG(TIMESTAMPDIFF(SECOND, created_at, last_retried)) secs FROM opendaylightjournal WHERE state="completed" %s' % op
cursor.execute(sql)
print(' Average processing time: %0.2fs' % cursor.fetchone()['secs'])
sql = (('SELECT object_type, operation, retry_count, object_uuid, TIMESTAMPDIFF(SECOND, created_at, last_retried) secs '
'FROM opendaylightjournal WHERE state="completed" %s ORDER BY TIMESTAMPDIFF(SECOND, created_at, last_retried) '
'DESC LIMIT %d') % (op, top_number))
cursor.execute(sql)
top_entries = cursor.fetchall()
print(' Top %d slow operations:' % top_number)
for n, entry in enumerate(top_entries, start=1):
print(' %(n)02d. %(op)s %(ot)s = %(secs)ss (%(r)s retries) [%(id)s]' %
{'n': n, 'op': entry['operation'], 'ot': entry['object_type'],
'secs': entry['secs'], 'r': entry['retry_count'],
'id': entry['object_uuid']})
print('ALL:')
profile()
print('')
print('CREATE:')
profile(op='create')
print('')
print('UPDATE:')
profile(op='update')
print('')
print('DELETE:')
profile(op='delete')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment