6

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

7

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

2

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.

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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