#!/usr/local/bin/python3.5
Import Pymysql
Import time
sum = 0
While True:
#open DB connection
db = Pymysql.connect (' localhost ', ' root ', ' abc-123 ', ' test ')
#use cursor ()
cursor = Db.cursor ()
#use execute () Run SQL
Cursor.execute ("Show variables like '%max_connections% ';")
#USE Fetchone ()
Max = Cursor.fetchone ()
Cursor.execute ("Show global Status Like ' Max_used_connections ';")
History_max = Cursor.fetchone ()
Cursor.execute ("Show global Status Like ' threads_connected ';")
currently = Cursor.fetchone ()
sum = sum + 1
Print ("\ n--------------------------------\ n")
Print ("Statistic Date:", Time.strftime ('%y-%m-%d%h:%m:%s '))
Print ("Current count:", sum)
Print ("MySQL max connections:", max[1])
Print ("MySQL History max connections:", history_max[1])
Print ("MySQL Current max connections:", currently[1])
Db.close ()
Time.sleep (5)
Output Result:
[Email protected] jb]#./mysql.py
--------------------------------
Statistics Date: 2016-05-25 09:31:52
Current number of statistics: 1
MySQL Maximum number of connections: 2000
MySQL history maximum number of connections: 6
Current maximum number of MySQL connections: 1
--------------------------------
Statistics Date: 2016-05-25 09:31:57
Current number of statistics: 2
MySQL Maximum number of connections: 2000
MySQL history maximum number of connections: 6
Current maximum number of MySQL connections: 1
--------------------------------
Statistics Date: 2016-05-25 09:32:02
Current number of statistics: 3
MySQL Maximum number of connections: 2000
MySQL history maximum number of connections: 6
Current maximum number of MySQL connections: 1
END!
Python monitors mysql max connections