Skip to content

Instantly share code, notes, and snippets.

@jesusangelm
Created May 19, 2011 17:26
Show Gist options
  • Select an option

  • Save jesusangelm/981280 to your computer and use it in GitHub Desktop.

Select an option

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
#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