Skip to content

Instantly share code, notes, and snippets.

@csfrancis
Created May 23, 2013 19:37
Show Gist options
  • Save csfrancis/5638827 to your computer and use it in GitHub Desktop.
Save csfrancis/5638827 to your computer and use it in GitHub Desktop.

Revisions

  1. csfrancis created this gist May 23, 2013.
    24 changes: 24 additions & 0 deletions ifstat_sys.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/bin/bash
    #
    # Show if stats by sampling /sys/.
    # Originally stolen from http://unix.stackexchange.com/questions/41346/upload-download-speed-in-tmux-status-line

    run_segment() {
    sleeptime="0.5"
    iface="eth0"
    RXB=$(</sys/class/net/"$iface"/statistics/rx_bytes)
    TXB=$(</sys/class/net/"$iface"/statistics/tx_bytes)
    sleep "$sleeptime"
    RXBN=$(</sys/class/net/"$iface"/statistics/rx_bytes)
    TXBN=$(</sys/class/net/"$iface"/statistics/tx_bytes)
    RXDIF=$(echo $((RXBN - RXB)) )
    TXDIF=$(echo $((TXBN - TXB)) )

    rx=$(echo "${RXDIF} / 1024 / ${sleeptime}" | bc)
    tx=$(echo "${TXDIF} / 1024 / ${sleeptime}" | bc)
    echo "${rx}K/s ⇈ ${tx}K/s"

    return 0
    }

    run_segment