Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # http://scratch-tales.blogspot.ru/
- #!/usr/local/bin/python2.7
- import subprocess
- import MySQLdb
- import datetime
- #connect to db and fetch result
- tempura_connect = MySQLdb.connect(host='127.0.0.1', port=3310, user='tempdbuser', passwd='tempdbuser', db='tempuradb')
- tempura_query = tempura_connect.cursor()
- #qresult = tempura_query.fetchall()
- pf_out = []
- p = subprocess.Popen('pfctl -sI -vv -i xl0', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- for line in p.stdout.readlines():
- pf_out.append(line)
- iBytes = pf_out[3].find('Bytes')
- BytesIn = pf_out[3].replace(']',' ')
- BytesIn = BytesIn[iBytes+6:]
- BytesIn = BytesIn.strip()
- iBytes = pf_out[5].find('Bytes')
- BytesOut = pf_out[5].replace(']',' ')
- BytesOut = BytesOut[iBytes+6:]
- BytesOut = BytesOut.strip()
- tempura_query.execute("""INSERT INTO net_storage (measure_time, bytes_in, bytes_out) VALUES (%s, %s, %s)""",(datetime.datetime.now(), BytesIn, BytesOut))
- tempura_connect.commit()
- retval = p.wait()
- tempura_query.close()
- tempura_connect.close()
Advertisement
Add Comment
Please, Sign In to add comment