Skip to content

Instantly share code, notes, and snippets.

@jvaubourg
Last active April 17, 2020 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvaubourg/15dbf25853fcae8c968fc9b6da7e0cf6 to your computer and use it in GitHub Desktop.
Save jvaubourg/15dbf25853fcae8c968fc9b6da7e0cf6 to your computer and use it in GitHub Desktop.
Dirty but simplest way to get a 95th percentile usage on a network interface
#!/bin/bash
netdev=eth0
storage=/tmp/95th_percentile_db
:> $storage
while true; do
rx_bytes_count1=$(awk "/${netdev}/ { print \$2 }" /proc/net/dev)
tx_bytes_count1=$(awk "/${netdev}/ { print \$10 }" /proc/net/dev)
sleep 5m
rx_bytes_count2=$(awk "/${netdev}/ { print \$2 }" /proc/net/dev)
tx_bytes_count2=$(awk "/${netdev}/ { print \$10 }" /proc/net/dev)
rx_Bps=$(( (rx_bytes_count2 - rx_bytes_count1) / 300 ))
tx_Bps=$(( (tx_bytes_count2 - tx_bytes_count1) / 300 ))
echo $(( rx_Bps + tx_Bps )) >> $storage
percentile95_index=$(( $(cat $storage | wc -l) * 95 / 100 ))
[ $percentile95_index -eq 0 ] && continue
percentile95_bps=$(( $(sort -n $storage | sed -n "${percentile95_index}p") * 8 ))
echo $percentile95_bps | numfmt --to=iec --suffix bps
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment