Created
May 19, 2011 17:26
-
-
Save jesusangelm/981280 to your computer and use it in GitHub Desktop.
Script para obtener los Mb enviados y recibidos por una interfaz de red determinada
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Script para obtener los Mb enviados y recibidos por | |
| #una interfaz de red determinada. | |
| #incluye una funcion para convertir Bytes a MB | |
| #tiene unas pequeñas fallas que pronto arreglare! :) | |
| def bytestomb bytes | |
| mb = bytes.to_f / (1024*1024) | |
| mb | |
| end | |
| interface= "ppp0" | |
| archivo = File.open('/proc/net/dev', 'r') | |
| archivo.each_line do |line| | |
| #puts line | |
| if line =~ /ppp0/ | |
| #puts line | |
| data = line.split('%s:' % interface)[1].split() | |
| rx_bytes = data[0] | |
| tx_bytes = data[8] | |
| puts "Recibidos: " + (bytestomb rx_bytes).to_s | |
| puts "Enviados: " + (bytestomb tx_bytes).to_s | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment