You are not logged in.

#1 2016-04-16 17:40:11

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 1,271
Website

Down/Up stats on tmux statusbar

Hi!

Just yesterday discovered this bash "tmux-networkspeed" script for generating network speed in the tmux statusline. << noted on the bottom right.

Place both bash scripts on "/usr/bin/" call it whatever you want, i named "muxi_dwnspeed" and "muxi_upspeed" (make sure you make it executable)

tmux-networkspeed

A bash script for generating network speed, for use in the tmux statusline split into up and down.

Shows speed in bytes, Ki, Mi and Gi , fakes fractions. Tested in Linux Mint/Ubuntu (Debian, looks fine to me). Doesn't currently work in in MAC OSX

Upload

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

sleep 2

TXBN=0
for txbytes in /sys/class/net/*/statistics/tx_bytes ; do
  let TXBN+=$(<$txbytes)
done
#divide by two for the period, multiply by 10 to allow a correct decimal place
TXDIF=$(echo $(((TXBN - TXB) * 5  )))

SPEEDU="↑ B/s"

if [ $TXDIF -ge 10240 ]; then
	SPEEDU="↑ Ki/s"
	TXDIF=$(echo $((TXDIF / 1024 )) )
fi

if [ $TXDIF -ge 10240 ]; then
	SPEEDU="↑ Mi/s"
	TXDIF=$(echo $((TXDIF / 1024 )) )
fi

if [ $TXDIF -ge 10240 ]; then
	SPEEDU="↑ Gi/s"
	TXDIF=$(echo $((TXDIF / 1024 )) )
fi

TXDIFF=$(($TXDIF % 10 ))
TXDIFI=$(( $TXDIF / 10 ))
TXDIF="$TXDIFI"

if [ $TXDIFF -ne 0 ]; then
	TXDIF=$( echo  "$TXDIFI.$TXDIFF" )
fi

echo "$TXDIF $SPEEDU"

Download

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

sleep 2

RXBN=0
for rxbytes in /sys/class/net/*/statistics/rx_bytes ; do
  let RXBN+=$(<$rxbytes)
done
#divide by two for the period, multiply by 10 to allow a correct decimal place
RXDIF=$(echo $(((RXBN - RXB) *5  )))

SPEEDD="↓ B/s"
if [ $RXDIF -ge 10240 ]; then
	SPEEDD="↓ Ki/s"
	RXDIF=$(echo $((RXDIF / 1024 )) )
fi

if [ $RXDIF -ge 10240 ]; then
	SPEEDD="↓ Mi/s"
	RXDIF=$(echo $((RXDIF / 1024 )) )
fi

if [ $RXDIF -ge 10240 ]; then
	SPEEDD="↓ Gi/s"
	RXDIF=$(echo $((RXDIF / 1024 )) )
fi
RXDIFF=$(($RXDIF % 10 ))
RXDIFI=$(( $RXDIF / 10 ))
RXDIF="$RXDIFI"

if [ $RXDIFF -ne 0 ]; then
	RXDIF=$( echo  "$RXDIFI.$RXDIFF" )
fi

echo "$RXDIF $SPEEDD"

On ".tmux.conf" i use:

# status right options

set -g status-right '#[fg=green]#[bg=default][#(muxi_upspeed)]#[default] #[fg=magenta]#[bg=][#(muxi_dwnspeed)]#[default]'

This code does not replace the good vnstat/vnstati, conky or other Linux net stats but it does great job showing dwn/up on tmux which really i like it, so i thought to share with anyone else that like using on tmux.

Thanks to author gryftir for making it done!

-EDIT-: corrected "upload code" sorry.

Nili

Last edited by Nili (2016-04-16 17:53:03)


Tumbleweed (Server) | KDE Plasma (Wayland)

Offline

#2 2016-04-16 18:15:31

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Down/Up stats on tmux statusbar

Very nice indeed, thanks Nili!
smile

Offline

#3 2016-04-17 13:45:07

Nili
Member
From: $HOME/♫♪
Registered: 2015-09-30
Posts: 1,271
Website

Re: Down/Up stats on tmux statusbar

Welcome HoaS wink


Tumbleweed (Server) | KDE Plasma (Wayland)

Offline

Board footer

Powered by FluxBB