Monitor the number of connections to clients on MySQL:
VI a1.py
#!/usr/bin/python
Import OS
Import datetime
D1 = Datetime.datetime.now (). Strftime ("%y-%m-%d%h:%m")
D2 = Datetime.datetime.now (). Strftime ("%y-%m-%d")
Os.system ('/bin/rm-rf/log/hosts/ date +%Y-%m-%d -d "7 days ago"
')
Os.system ('/bin/netstat-anp | grep 10.0.0.2:3306 >/log/hosts/mysqls.txt ')
D3 = Os.path.join ("/log/hosts", D2)
D4 = Os.path.join (D3, "Mysqls2.txt")
d5 = Os.path.join (D3, "Mysqls3.txt")
If not os.path.exists (D3):
Os.makedirs (D3)
Os.mknod (D4)
Os.mknod (D5)
Os.remove (D5)
Os.mknod (D5)
list = []
A = open ('/log/hosts/mysqls.txt ', ' R ')
b = A.readlines ()
A.close ()
For C in B:
D = C.split () [4]
E = D.split (":") [0]
List.append (e)
E2 = Set (list)
h = open (D4, ' a ')
H.write ("" + "\ n")
H.write (str (d1) + "\ n")
H.write ("" + "\ n")
H.close ()
For F in E2:
g = List.count (f)
G2 = ('%s:%s '% (f,g))
H2 = open (D4, ' a ')
H2.write (g2+ "\ n")
H2.close ()
If G >= 1200:
h3 = open (D5, ' a ')
H3.write (g2+ "\ n")
H3.close ()
: Wq
Python a1.py
Monitor the number of connections to clients on MySQL