#!/usr/bin/python import commands import time cmd = "echo `/opt/sbin/unbound-control stats | egrep -e 'total.num.queries' -e 'time.elapsed' | sed -e 's/.*=//'`" f = open("/opt/bin/dns_query_log.txt", "a") oldtotal = float(0) while 1: #start_time = int(time.time()) output = commands.getoutput(cmd).split() #print output #end_time = int(time.time()) #run_time = end_time - start_time newtotal = float(output[0]) date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) tqs = newtotal - oldtotal elapsed = float(output[1]) qps = tqs / elapsed f.write("%s\t%f\t%f\t%f\n" %(date, tqs, elapsed, qps)) f.flush() #print "old value: %f" %oldtotal #print "new value: %f" %newtotal oldtotal = newtotal time.sleep(60) f.close()