Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to get upload and download speeds in Tmux's status line?

share|improve this question

3 Answers 3

You can call a shell script from tmux's status line, specifying your required interface like so:

set -g status-left '#[fg=blue]#(speed eth0)#[default]'

And place this script, speed1, in your $PATH:

#!/bin/bash

iface=$1
RXB=$(</sys/class/net/"$iface"/statistics/rx_bytes)
TXB=$(</sys/class/net/"$iface"/statistics/tx_bytes)
sleep 2 
RXBN=$(</sys/class/net/"$iface"/statistics/rx_bytes)
TXBN=$(</sys/class/net/"$iface"/statistics/tx_bytes)
RXDIF=$(echo $((RXBN - RXB)) )
TXDIF=$(echo $((TXBN - TXB)) )

echo -e "$((RXDIF / 1024 / 2))K/s $((TXDIF / 1024 / 2))K/s"

1. Can't remember where I found this...

share|improve this answer
    
Seems to work. Thank you @jasonwryan. –  Sol Jun 22 '12 at 11:57
1  
@Sol, you should mark the answer as accepted then ... –  maxschlepzig Jun 23 '12 at 9:29

I wanted the answer above by jasonwryan to deal with all interfaces so I made this modification:

#!/bin/bash
RXB=0
TXB=0
for rxbytes in /sys/class/net/*/statistics/rx_bytes ; do
  let RXB+=$(<$rxbytes)
done
for txbytes in /sys/class/net/*/statistics/tx_bytes ; do
  let TXB+=$(<$txbytes)
done

sleep 2 

RXBN=0
TXBN=0
for rxbytes in /sys/class/net/*/statistics/rx_bytes ; do
  let RXBN+=$(<$rxbytes)
done
for txbytes in /sys/class/net/*/statistics/tx_bytes ; do
  let TXBN+=$(<$txbytes)
done    
RXDIF=$(echo $((RXBN - RXB)) )
TXDIF=$(echo $((TXBN - TXB)) )

echo -e "$((RXDIF / 1024 / 2))K/s $((TXDIF / 1024 / 2))K/s"

You can obviously change the wildcard to only do all eth* or wlan* interfaces, or use find to make a more complicated match of the two.

share|improve this answer

Building on the Above, this should display up and down indicators using ^ and v, use the correct symbol (Ki is binary Kilobytes, etc) change to Mi and Gi as needed, and also display non zero fractional values of one decimal place.

https://github.com/gryftir/tmux-networkspeed

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.