Guest User

Untitled

a guest
Apr 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class NetTraffic < Widget
  2. description "Network traffic information"
  3. option :iface, "Network interface", "eth0"
  4. option :max_up, "Max up", 56
  5. option :max_down, "Max down", 56
  6. field :up, "Upload rate in kB/s", 0
  7. field :down, "Download rate in kB/s", 0
  8. field :uptotal, "Amount of data uploaded in kB/s", 0
  9. field :downtotal, "Amount of data downloaded in kB/s", 0
  10. field :percentage_up, "Percentage up"
  11. field :percentage_down, "Percentage down"
  12. default "@percentage_down"
  13.  
  14. init do
  15. dev = ProcFile.parse_file("net/dev")[2][@iface].split
  16. first_down = dev[0].to_f
  17. first_up = dev[8].to_f
  18. sleep 1
  19. dev = ProcFile.parse_file("net/dev")[2][@iface].split
  20. second_down = dev[0].to_f
  21. second_up = dev[8].to_f
  22. @down = (second_down - first_down) / 1024
  23. @downtotal = second_down / 1024
  24. @up = (second_up - first_up) / 1024
  25. @uptotal = second_up / 1024
  26. @percentage_up = @up * 100 / @max_up
  27. @percentage_down = @down * 100 / @max_down
  28. end
  29. end
Add Comment
Please, Sign In to add comment