¿Cómo puedo obtener las estadísticas actuales de rendimiento de la interfaz de red en Linux/UNIX? [cerrado]
Herramientas como MRTG proporcionan gráficos de rendimiento / ancho de banda de la red para el uso actual de la red en interfaces específicas, como eth0. ¿Cómo puedo devolver esa información en la línea de comandos en Linux / UNIX?
Preferiblemente esto sería sin instalar nada más que lo que está disponible en el sistema como estándar.
15 answers
Puede analizar la salida de ifconfig
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-02-27 20:45:30
iftop does for network usage what top(1) does for CPU usage
-- http://www.ex-parrot.com/~pdw/iftop/
No se como es "standard" iftop, pero pude instalarlo con yum install iftop
en Fedora.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-20 19:01:33
¿Tienes sar? Probablemente sí si estás usando RHEL / CentOS.
No hay necesidad de priv, binarios dorky, scripts hacky, libpcap, etc. Ganar.
$ sar -n DEV 1 3
Linux 2.6.18-194.el5 (localhost.localdomain) 10/27/2010
02:40:56 PM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
02:40:57 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:40:57 PM eth0 10700.00 1705.05 15860765.66 124250.51 0.00 0.00 0.00
02:40:57 PM eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:40:57 PM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
02:40:58 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:40:58 PM eth0 8051.00 1438.00 11849206.00 105356.00 0.00 0.00 0.00
02:40:58 PM eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:40:58 PM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
02:40:59 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:40:59 PM eth0 6093.00 1135.00 8970988.00 82942.00 0.00 0.00 0.00
02:40:59 PM eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: eth0 8273.24 1425.08 12214833.44 104115.72 0.00 0.00 0.00
Average: eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-10-27 19:04:44
Escribí este script tonto hace mucho tiempo, no depende más que de Perl y Linux≥2.6:
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
use Time::HiRes qw(gettimeofday usleep);
my $dev = @ARGV ? shift : 'eth0';
my $dir = "/sys/class/net/$dev/statistics";
my %stats = do {
opendir +(my $dh), $dir;
local @_ = readdir $dh;
closedir $dh;
map +($_, []), grep !/^\.\.?$/, @_;
};
if (-t STDOUT) {
while (1) {
print "\033[H\033[J", run();
my ($time, $us) = gettimeofday();
my ($sec, $min, $hour) = localtime $time;
{
local $| = 1;
printf '%-31.31s: %02d:%02d:%02d.%06d%8s%8s%8s%8s',
$dev, $hour, $min, $sec, $us, qw(1s 5s 15s 60s)
}
usleep($us ? 1000000 - $us : 1000000);
}
}
else {print run()}
sub run {
map {
chomp (my ($stat) = slurp("$dir/$_"));
my $line = sprintf '%-31.31s:%16.16s', $_, $stat;
$line .= sprintf '%8.8s', int (($stat - $stats{$_}->[0]) / 1)
if @{$stats{$_}} > 0;
$line .= sprintf '%8.8s', int (($stat - $stats{$_}->[4]) / 5)
if @{$stats{$_}} > 4;
$line .= sprintf '%8.8s', int (($stat - $stats{$_}->[14]) / 15)
if @{$stats{$_}} > 14;
$line .= sprintf '%8.8s', int (($stat - $stats{$_}->[59]) / 60)
if @{$stats{$_}} > 59;
unshift @{$stats{$_}}, $stat;
pop @{$stats{$_}} if @{$stats{$_}} > 60;
"$line\n";
} sort keys %stats;
}
sub slurp {
local @ARGV = @_;
local @_ = <>;
@_;
}
Solo lee de /sys/class/net/$dev/statistics
cada segundo, e imprime los números actuales y la tasa media de cambio:
$ ./net_stats.pl eth0
rx_bytes : 74457040115259 4369093 4797875 4206554 364088
rx_packets : 91215713193 23120 23502 23234 17616
...
tx_bytes : 90798990376725 8117924 7047762 7472650 319330
tx_packets : 93139479736 23401 22953 23216 23171
...
eth0 : 15:22:09.002216 1s 5s 15s 60s
^ current reading ^-------- averages ---------^
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-03 12:30:26
Nload es una gran herramienta para monitorear el ancho de banda en tiempo real y se instala fácilmente en Ubuntu o Debian con sudo apt-get install nload.
Device eth0 [10.10.10.5] (1/2):
=====================================================================================
Incoming:
. ...|
# ####|
.. |#| ... #####. .. Curr: 2.07 MBit/s
###.### #### #######|. . ## | Avg: 1.41 MBit/s
########|#########################. ### Min: 1.12 kBit/s
........ ################################### .### Max: 4.49 MBit/s
.##########. |###################################|##### Ttl: 1.94 GByte
Outgoing:
########## ########### ###########################
########## ########### ###########################
##########. ########### .###########################
########### ########### #############################
########### ###########..#############################
############ ##########################################
############ ##########################################
############ ########################################## Curr: 63.88 MBit/s
############ ########################################## Avg: 32.04 MBit/s
############ ########################################## Min: 0.00 Bit/s
############ ########################################## Max: 93.23 MBit/s
############## ########################################## Ttl: 2.49 GByte
Otra herramienta excelente es iftop, también fácilmente apt-get'aable:
191Mb 381Mb 572Mb 763Mb 954Mb
└────────────┴──────────┴─────────────────────┴───────────┴──────────────────────
box4.local => box-2.local 91.0Mb 27.0Mb 15.1Mb
<= 1.59Mb 761kb 452kb
box4.local => box.local 560b 26.8kb 27.7kb
<= 880b 31.3kb 32.1kb
box4.local => userify.com 0b 11.4kb 8.01kb
<= 1.17kb 2.39kb 1.75kb
box4.local => b.resolvers.Level3.net 0b 58b 168b
<= 0b 83b 288b
box4.local => stackoverflow.com 0b 42b 21b
<= 0b 42b 21b
box4.local => 224.0.0.251 0b 0b 179b
<= 0b 0b 0b
224.0.0.251 => box-2.local 0b 0b 0b
<= 0b 0b 36b
224.0.0.251 => box.local 0b 0b 0b
<= 0b 0b 35b
─────────────────────────────────────────────────────────────────────────────────
TX: cum: 37.9MB peak: 91.0Mb rates: 91.0Mb 27.1Mb 15.2Mb
RX: 1.19MB 1.89Mb 1.59Mb 795kb 486kb
TOTAL: 39.1MB 92.6Mb 92.6Mb 27.9Mb 15.6Mb
¡No te olvides de las clásicas y potentes utilidades sar y netstat en las antiguas *nix!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-04-09 22:32:59
Puedes analizar /proc/net/dev.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-02-27 20:54:57
-
dstat
- Combina información de vmstat, iostat, ifstat, netstat y más -
iftop
- Increíble utilidad de ancho de banda de red para analizar lo que realmente está sucediendo en su eth -
netio
- Mide el rendimiento neto de una red a través de TCP/IP -
inq
- Utilidad de solución de problemas de CLI que muestra información sobre el almacenamiento, normalmente Symmetrix. De forma predeterminada, INQ devuelve el nombre del dispositivo, el ID de Symmetrix, el LUN de Symmetrix y la capacidad. -
send_arp
- Envía una emisión arp en el dispositivo de red especificado (el valor predeterminado es eth0), que informa de una asignación de direcciones IP antigua y nueva a una dirección MAC. -
EtherApe
- es un monitor de red gráfico para Unix modelado después de etherman. Con los modos de capa de enlace, IP y TCP, muestra la actividad de la red gráficamente. -
iptraf
: un monitor de tráfico IP que muestra información sobre el tráfico IP que pasa por la red.
Más detalles: http://felipeferreira.net/?p=1194
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-20 19:00:11
Además de iftop e iptraf, también verifique:
-
bwm-ng
(Monitor de Ancho de Banda de Próxima Generación)
Y / o
-
cbm
(Medidor de Ancho de banda de color)
Ref: http://www.powercram.com/2010/01/bandwidth-monitoring-tools-for-ubuntu.html
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-20 19:00:41
Tengo otro script de quick'n'dirty bash para eso:
#!/bin/bash
IF=$1
if [ -z "$IF" ]; then
IF=`ls -1 /sys/class/net/ | head -1`
fi
RXPREV=-1
TXPREV=-1
echo "Listening $IF..."
while [ 1 == 1 ] ; do
RX=`cat /sys/class/net/${IF}/statistics/rx_bytes`
TX=`cat /sys/class/net/${IF}/statistics/tx_bytes`
if [ $RXPREV -ne -1 ] ; then
let BWRX=$RX-$RXPREV
let BWTX=$TX-$TXPREV
echo "Received: $BWRX B/s Sent: $BWTX B/s"
fi
RXPREV=$RX
TXPREV=$TX
sleep 1
done
Está considerando que sleep 1
realmente durará exactamente un segundo, lo que no es cierto, pero lo suficientemente bueno para una evaluación aproximada del ancho de banda.
Gracias a @ephemient por el /sys/class/net/<interface>
! :)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-14 06:45:53
Me gusta iptraf
pero probablemente tenga que instalarlo y parece que ya no se mantiene activamente.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-02-27 20:44:32
Si solo quieres obtener el valor, puedes usar simple shell oneliner de esta manera:
S=10; F=/sys/class/net/eth0/statistics/rx_bytes; X=`cat $F`; sleep $S; Y=`cat $F`; BPS="$(((Y-X)/S))"; echo $BPS
Le mostrará el promedio de "bytes recibidos por segundo" para un período de 10 segundos (puede cambiar el período cambiando el parámetro S=10
, y puede medir BPS transmitidos en lugar de BPS recibidos usando tx_bytes
en lugar de rx_bytes
). No olvide cambiar eth0
al dispositivo de red que desea monitorear.
Por supuesto, usted no está limitado a mostrar la tasa media (como se menciona en otros respuestas, hay otras herramientas que le mostrarán una salida mucho mejor), pero esta solución es fácilmente scriptable para hacer otras cosas.
Por ejemplo, el siguiente script de shell (dividido en varias líneas para facilitar la lectura) ejecutará el proceso offlineimap solo cuando la velocidad promedio de transmisión de 5 minutos caiga por debajo de 10Kbps (presumiblemente, cuando termine algún otro proceso que consume ancho de banda):
#!/bin/sh
S=300; F=/sys/class/net/eth0/statistics/tx_bytes
BPS=999999
while [ $BPS -gt 10000 ]
do
X=`cat $F`; sleep $S; Y=`cat $F`; BPS="$(((Y-X)/S))";
echo BPS is currently $BPS
done
offlineimap
Tenga en cuenta que /sys/class/...
es específico de Linux (lo cual está bien, ya que el remitente eligió la etiqueta linux
), y necesita núcleo no arcaico. El código shell en sí es compatible con / bin / sh (así que no solo bash, sino dash y otras implementaciones de /bin/sh funcionarán) y /bin/sh es algo que realmente siempre está instalado.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-20 13:10:06
Encuentro que dstat es bastante bueno. Tiene que ser instalado sin embargo. Te da más información de la que necesitas. Netstat le dará tarifas de paquetes, pero no bandwith también. netstat-s
Puede usar iperf para comparar el rendimiento de la red ( rendimiento máximo posible). Vea los siguientes enlaces para más detalles:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-28 20:02:12
No pude conseguir que el script de análisis ifconfig funcionara para mí en una AMI, así que conseguí que esto funcionara midiendo el tráfico recibido promediado durante 10 segundos
date && rxstart=`ifconfig eth0 | grep bytes | awk '{print $2}' | cut -d : -f 2` && sleep 10 && rxend=`ifconfig eth0 | grep bytes | awk '{print $2}' | cut -d : -f 2` && difference=`expr $rxend - $rxstart` && echo "Received `expr $difference / 10` bytes per sec"
Lo siento, es siempre tan barato y desagradable, pero funcionó!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-25 14:39:48
ifconfig -a
ip -d link
ls -l /sys/class/net/ (physical and virtual devices)
route -n
Si quieres la salida de (ifconfig-a) en formato json puedes usar this (python)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-16 11:41:50