Guest User

Untitled

a guest
May 20th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import time
  4.  
  5. TIMEFORMAT = "%m/%d/%y %H:%M:%S"
  6. INTERVAL = 2
  7.  
  8. def getTimeList():
  9. statFile = file("/proc/stat", "r")
  10. timeList = statFile.readline().split(" ")[2:6]
  11. statFile.close()
  12. for i in range(len(timeList)) :
  13. timeList[i] = int(timeList[i])
  14. return timeList
  15.  
  16. def deltaTime(interval) :
  17. x = getTimeList()
  18. time.sleep(interval)
  19. y = getTimeList()
  20. for i in range(len(x)) :
  21. y[i] -= x[i]
  22. return y
  23.  
  24. if __name__ == "__main__" :
  25. while True :
  26. dt = deltaTime(INTERVAL)
  27. timeStamp = time.strftime(TIMEFORMAT)
  28. cpuPct = 100 - (dt[len(dt) - 1] * 100.00 / sum(dt))
  29. print timeStamp + "\t" + str('%.4f' %cpuPct)
Add Comment
Please, Sign In to add comment