Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3.4
- import mysql.connector
- import time
- import subprocess
- import getopt
- import sys
- import mysql.connector
- import time
- def main():
- try:
- opts, args = getopt.getopt(sys.argv[1:], "ho:l:v", ["help", "outfile=", "load="])
- except getopt.GetoptError as err:
- print (str(err))
- usage()
- sys.exit(2)
- outfile = None
- verbose = False
- for o, a in opts:
- if o == '-v':
- verbose = True
- elif o in ("-h", "--help"):
- usage()
- sys.exit()
- elif o in ("-o", "--outfile"):
- outfile = a
- elif o in ("-l", "--loadlimit"):
- loadlimit = a
- else:
- assert False, "bip boop error with args"
- cnx = mysql.connector.connect(user='root', password='1234', host='localhost')
- cursor = cnx.cursor()
- result_file = open(outfile, 'w')
- p = re.compile("load average: ([0-9]*[.][0-9]+)")
- while True:
- cursor.execute("show full processlist")
- processlist = cursor.fetchall()
- uptime = subprocess.Popen("uptime")
- time.sleep(1);
- p.search(uptime)
- if(_.group(1) > loadlimit):
- result_file.write(processlist)
- result_file.write(uptime)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement