Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
from logentries import LogentriesHandler
import pymysql
import os
import logging
from ManageCluster import ManageAuroraCluster as mc
def handler(event, context):
hostsandentries = {}
mysqluser = os.environ['MYSQLUSER']
mysqlpassword = os.environ['MYSQLPASSWORD']
log = logging.getLogger('logentries')
prodclusters = mc.getClustersByTag(mc.getClusters(), "realm", os.environ['REALM'])
prodnodes = []
for cluster in prodclusters:
nodes = mc.getClusterNodes(cluster)
for node in nodes:
lognodes = []
for node in prodnodes:
db = pymysql.connect(node, user=mysqluser, passwd=mysqlpassword, db='mysql', connect_timeout=5)
cursor = db.cursor()
cursor.execute("SELECT COUNT(*) FROM slow_log")
for row in cursor.fetchone():
if row > 0:
cursor.execute("SELECT * FROM slow_log_backup")
for row in cursor.fetchall():
resultstring = "\n Start time: %s \n User and host: %s\n Query Time:%s\n Lock time:%s\n Rows sent:%s\n Rows examined: %s\n Database: %s\n Last insert id: %s\n Insert id: %s\n Server id:%s\n SQL text: %s\n Thread id: %s" % (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11])
return hostsandentries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment