6

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

3 Answers 3

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
  • Why do you read rx_bytes twice then take the difference and then divide by the amount you slept. exspecially why do divide by the sleeptime? or is this just coincidence? Commented Feb 8, 2024 at 10:00
  • Oh... now i see. we want to display Kb per >second<. because we measure how many bytes passed between the two measurements we have to divide by the sleeptime to calculate the Kb/s Commented Feb 8, 2024 at 10:05
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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.