maxxximatoze | Ci-dessous deux scripts GPL sans prétention aucune qui vous permettrons de monitorer en temps réel les IOs et les débits en lecture et écriture de votre disque dur ainsi que les debits réseau. Si ça vous plait (ou pas d'ailleur) ou si vous avez des commentaires ou idées pour améliorer la chose, ne vous genez pas. Testés sur ubuntu 6.06, 8.04, 9.04, 9.10, opensuse 10, 11, 11.1, sles 10sp2 et 11, fedora 9 et plus, ils sont maintenant configurables au niveau du délai de rafraichissement et beaucoup plus précis grâce à un système de compensation du temps d'exécution et une priorité accrue, ainsi qu'un contrôle de dépassement de la compensation pour garantir la précision de la mesure. Capablent de mesurer de très gros débits grâce au changement automatique des unités à l'affichage, je m'en sert lors d'installation de gros sytèmes de virtualisation pour aider troubleshooter les problèmes d'io. Redoutable. PS: ne pas oublier de copier les scripts dans /usr/sbin et de les passer en exécutable... Edit: maj du script en 0.2 Edit: maj du script en 0.4 Edit: Ajout de netview 0.2 Edit: maj de ioviex en 0.6 Edit: maj de netview en 0.6 Edit: maj de ioview et netview en 0.8 Edit: maj de ioview et netview en 0.9 Edit: maj de ioview et netview en 0.95 Edit: maj de ioview et netview en 0.97 Edit: maj de ioview et netview en 0.99 Edit: maj de ioview et netview en 0.9999 Edit: Enfin la v1.0 ! Edit: maj de ioview et netview en 1.01 Edit: maj de ioview et netview en 1.02 Edit: maj de ioview et netview en 1.04 ci-dessous ce que ca donne à l'écran (si tout va bien) sur une carte adaptec 5085 en lecture séquentielle et un bond en mode 0 de deux carte intel 10GE (bridées car sur port pcie 4X au lieu de 8), et oui oui les chiffres sont bons. pour ioview
Real time statistics for sdc (refreshed every 3 sec) Reads per second: 6244.33r/s Average read size: 256.0KiB/s Merged reads per second: 0r/s Read throughput: 1.524GiB/s Writes per second: 2.66w/s Average write size: 6.6KiB/s Merged writes per second: .66w/s Write throughput: 17.6KiB/s Total reads: 624012 Total average read size: 252.6KiB Total merged reads: 5210 Total data read: 157656278KiB 153961.20MiB 150.352GiB .1468TiB Total writes: 335485 Total average write size: 27.4KiB Total merged writes: 936940 Total data written: 9197405KiB 8981.84MiB 8.771GiB .0085TiB
|
et pour netview
Real time statistics for bond1 (refreshed every 3 sec) Link encap:Ethernet HWaddr 00:1B:21:2C:28:D4 inet addr:10.0.0.2 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:184691251 errors:0 dropped:0 overruns:0 frame:0 TX packets:208073052 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:239703181513 (228598.7MiB) TX bytes:277194877850 (264353.6MiB) RX packets per second: 927145.00pkt/s RX average packet size: 1513.94bytes/pkt RX throughput: 11.229Gb/s (1.307GiB/s) TX packets per second: 123557.00pkt/s TX average packet size: 54.00bytes/pkt TX throughput: 53.38Mb/s (6.36MiB/s)
| Ci dessous ioview: #!/bin/bash # Author: Maxime Pierron # # /usr/sbin/ioview # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ramfs="/tmpramfs" function usage() { echo "ioview v1.04 by Maxime Pierron, 2007, 2008, 2009." echo "On screen real time block device utilization rate," echo "a 2.6.x linux kernel is required." echo "Usage: ioview "time_in_sec" "device_name" (ex: ioview 1 sda)," echo "use "time_in_sec" to specify the refresh interval," echo "(default: 3s, 0 to display only once)," echo "press ctrl+C to stop ioview." } function float_cond() { local cond=0 if [ $# -gt 0 ]; then cond=$(echo "$*"|bc 2>/dev/null -q 2>/dev/null) if [ -z "$cond" ]; then cond=0; fi if [[ "$cond" != 0 && "$cond" != 1 ]]; then cond=0; fi fi local stat=$((cond == 0)) return $stat } if [ -z $1 ]; then usage exit 0 fi if [ -z $(find /usr/bin/ -name awk|sed 's;/usr/bin/;;g') ]; then echo "awk is missing, you have to install it."; exit 1; fi if [ -z $(find /usr/bin/ -name bc|sed 's;/usr/bin/;;g') ]; then echo "bc is missing, you have to install it."; exit 1; fi oneshot="emtpy" if [ ! -z $2 ]; then if [ $1 -eq 0 ]; then rr=1 dsk=$2 oneshot="true" else if [ $1 -ge 1 ]; then rr=$1 dsk=$2 else usage echo "You must enter an integer." exit 1 fi fi else rr=3 dsk=$1 fi device=$(awk '/'" $dsk "'/ {print $3}' /proc/diskstats) if [ ! -z $device ]; then device=$(awk '/'" $dsk "'/ {print $8}' /proc/diskstats) if [ -z $device ]; then usage echo $dsk "is not a usable block device." exit 1 fi else usage echo $dsk "not found." exit 1 fi pid=$$ renice -19 $pid > /dev/null 2>&1 if [ ! -d $ramfs ]; then mkdir $ramfs fi if [ -z $(mount|grep "$ramfs"|sed -n "1{p;q;}"|awk '{print $1}') ]; then mount -t tmpfs -o size=4M, tmpfs $ramfs > /dev/null 2>&1 fi diskstats=$(ls $ramfs|grep diskstats.); for i in $diskstats; do pidlock=$(echo $i|cut -d"." -f2); if [ -z $(pidstat -p $pidlock 2>/dev/null|awk '{print $2}'|grep $pidlock) ]; then rm -f $ramfs/$i; fi; done cat /proc/diskstats > $ramfs/diskstats.$pid read read0 mergedread0 readsector0 write0 mergedwrite0 writesector0 <<< $(awk '{print $4,$5,$6,$8,$9,$10}' <<< $(awk '/'" $dsk "'/' $ramfs/diskstats.$pid 2>/dev/null)) unit1="r/s" unit2="w/s" unit3="KiB/s" unit4="KiB" unit5="MiB" unit6="GiB" unit7="TiB" message="refreshed every $rr sec" while [ 1 ]; do date0=$(date +%s.%N) cat /proc/diskstats > $ramfs/diskstats.$pid read1=$read0 mergedread1=$mergedread0 readsector1=$readsector0 write1=$write0 mergedwrite1=$mergedwrite0 writesector1=$writesector0 read read0 mergedread0 readsector0 write0 mergedwrite0 writesector0 <<< $(awk '{print $4,$5,$6,$8,$9,$10}' <<< $(awk '/'" $dsk "'/' $ramfs/diskstats.$pid 2>/dev/null)) reads=$(echo "scale=2; ($read0-$read1)/$rr"|bc 2>/dev/null) mergedreads=$(echo "scale=2; ($mergedread0-$mergedread1)/$rr"|bc 2>/dev/null) readkB=$(echo "scale=2; ($readsector0-$readsector1)*512/1024"|bc 2>/dev/null) if float_cond $reads '>' 0; then avgreadsz=$(echo "scale=1; $readkB/$reads/$rr"|bc 2>/dev/null) else avgreadsz=0 fi readspeed=$(echo "scale=1; $readkB/$rr"|bc 2>/dev/null) readspeedunit="KiB/s" if float_cond $readspeed '>=' 1024; then readspeed=$(echo "scale=2; $readkB/1024/$rr"|bc 2>/dev/null) readspeedunit="MiB/s" if float_cond $readspeed '>=' 1024; then readspeed=$(echo "scale=3; $readkB/1048576/$rr"|bc 2>/dev/null) readspeedunit="GiB/s" fi fi datareadk=$[$readsector0*512/1024] totavgreadsz=$(echo "scale=1; $datareadk/$read0"|bc 2>/dev/null) if [ -z $totavgreadsz ]; then totavgreadsz=0; fi datareadm=$(echo "scale=2; $datareadk/1024"|bc 2>/dev/null) datareadg=$(echo "scale=3; $datareadm/1024"|bc 2>/dev/null) datareadt=$(echo "scale=4; $datareadg/1024"|bc 2>/dev/null) writes=$(echo "scale=2; ($write0-$write1)/$rr"|bc 2>/dev/null) mergedwrites=$(echo "scale=2; ($mergedwrite0-$mergedwrite1)/$rr"|bc 2>/dev/null) writekB=$(echo "scale=2; ($writesector0-$writesector1)*512/1024"|bc 2>/dev/null) if float_cond $writes '>' 0; then avgwritesz=$(echo "scale=1; $writekB/$writes/$rr"|bc 2>/dev/null) else avgwritesz=0 fi writespeed=$(echo "scale=1; $writekB/$rr"|bc 2>/dev/null) writespeedunit="KiB/s" if float_cond $writespeed '>=' 1024; then writespeed=$(echo "scale=2; $writekB/1024/$rr"|bc 2>/dev/null) writespeedunit="MiB/s" if float_cond $writespeed '>=' 1024; then writespeed=$(echo "scale=3; $writekB/1048576/$rr"|bc 2>/dev/null) writespeedunit="GiB/s" fi fi datawritek=$[$writesector0*512/1024] totavgwritesz=$(echo "scale=1; $datawritek/$write0"|bc 2>/dev/null) if [ -z $totavgwritesz ]; then totavgwritesz=0; fi datawritem=$(echo "scale=2; $datawritek/1024"|bc 2>/dev/null) datawriteg=$(echo "scale=3; $datawritem/1024"|bc 2>/dev/null) datawritet=$(echo "scale=4; $datawriteg/1024"|bc 2>/dev/null) if [ $oneshot = "true" ];then message="displayed only once" oneshot="false" else clear echo "Real time statistics for $dsk ($message)" echo "" echo "Reads per second:_$reads$unit1"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Average read size:_$avgreadsz$unit3"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Merged reads per second:_$mergedreads$unit1"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Read throughput:_$readspeed$readspeedunit"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "" echo "Writes per second:_$writes$unit2"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Average write size:_$avgwritesz$unit3"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Merged writes per second:_$mergedwrites$unit2"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Write throughput:_$writespeed$writespeedunit"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "" echo "Total reads:_$read0"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Total average read size:_$totavgreadsz$unit4"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Total merged reads:_$mergedread0"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Total data read:_$datareadk$unit4 $datareadm$unit5 $datareadg$unit6 $datareadt$unit7"|awk -F"_" '{printf("%-25s %-1s %-1s %-1s \n", $1, $2, $3, $4)}' echo "" echo "Total writes:_$write0"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Total average write size:_$totavgwritesz$unit4"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Total merged writes:_$mergedwrite0"|awk -F"_" '{printf("%-25s %-1s \n", $1, $2)}' echo "Total data written:_$datawritek$unit4 $datawritem$unit5 $datawriteg$unit6 $datawritet$unit7"|awk -F"_" '{printf("%-25s %-1s %-1s %-1s \n", $1, $2, $3, $4)}' if [ $oneshot = "false" ];then exit 0; fi fi date1=$(date +%s.%N) offset=$(echo "scale=6; $date1-$date0"|bc 2>/dev/null) sleeptime=$(echo "scale=6; $rr-($offset*1.11)"|bc 2>/dev/null) if float_cond $sleeptime '<=' 0; then sleeptime=0.001 echo "WARNING: Results are not accurate due to too high system load." fi sleep $sleeptime 2> /dev/null done
| Et ci dessous netview: #!/bin/bash # Author: Maxime Pierron # # /usr/sbin/netview # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ramfs="/tmpramfs" function usage() { echo "netview v1.04 by Maxime Pierron, 2007, 2008, 2009." echo "On screen real time net device utilization rate," echo "a 2.6.x linux kernel is required." echo "Usage: netview "time_in_sec" "device_name" (ex: netview 1 eth0)," echo "use "time_in_sec" to specify the refresh interval," echo "(default: 3s, 0 to display only once)," echo "press ctrl+C to stop netview." } function float_cond() { local cond=0 if [ $# -gt 0 ]; then cond=$(echo "$*"|bc 2>/dev/null -q 2>/dev/null) if [ -z "$cond" ]; then cond=0; fi if [[ "$cond" != 0 && "$cond" != 1 ]]; then cond=0; fi fi local stat=$((cond == 0)) return $stat } if [ -z $1 ]; then usage exit 0 fi if [ -z $(find /usr/bin/ -name awk|sed 's;/usr/bin/;;g') ]; then echo "awk is missing, you have to install it."; exit 1; fi if [ -z $(find /usr/bin/ -name bc|sed 's;/usr/bin/;;g') ]; then echo "bc is missing, you have to install it."; exit 1; fi oneshot="emtpy" if [ ! -z $2 ]; then if [ $1 -eq 0 ]; then rr=1 iface=$2 oneshot="true" else if [ $1 -ge 1 ]; then rr=$1 iface=$2 else usage echo "You must enter an integer." exit 1 fi fi else rr=3 iface=$1 fi device=$(grep -w $iface /proc/net/dev|cut -d ":" -f1) if [ -z $device ]; then usage echo $iface "not found." exit 1 fi pid=$$ renice -19 $pid > /dev/null 2>&1 if [ ! -d $ramfs ]; then mkdir $ramfs fi if [ -z $(mount|grep "$ramfs"|sed -n "1{p;q;}"|awk '{print $1}') ]; then mount -t tmpfs -o size=4M, tmpfs $ramfs > /dev/null 2>&1 fi netdev=$(ls $ramfs|grep netdev.); for i in $netdev; do pidlock=$(echo $i|cut -d"." -f2); if [ -z $(pidstat -p $pidlock 2>/dev/null|awk '{print $2}'|grep $pidlock) ]; then rm -f $ramfs/$i; fi; done cat /proc/net/dev > $ramfs/netdev.$pid read rxbytes0 rxpackets0 txbytes0 txpackets0 <<< $(awk '{print $1,$2,$9,$10}' <<< $(grep $iface $ramfs/netdev.$pid 2>/dev/null|cut -d":" -f2)) pkts="pkt/s" bytes="bytes/pkt" message="refreshed every $rr sec" while [ 1 ]; do date0=$(date +%s.%N) cat /proc/net/dev > $ramfs/netdev.$pid rxbytes1=$rxbytes0 rxpackets1=$rxpackets0 txbytes1=$txbytes0 txpackets1=$txpackets0 read rxbytes0 rxpackets0 txbytes0 txpackets0 <<< $(awk '{print $1,$2,$9,$10}' <<< $(grep $iface $ramfs/netdev.$pid 2>/dev/null|cut -d":" -f2)) rxpackets=$(echo "scale=2; ($rxpackets0-$rxpackets1)/$rr"|bc 2>/dev/null) rxbytes=$(echo "scale=2; ($rxbytes0-$rxbytes1)/$rr"|bc 2>/dev/null) if float_cond $rxpackets '>' 0; then avgrxsz=$(echo "scale=2; $rxbytes/$rxpackets"|bc 2>/dev/null) else avgrxsz=0 fi rxkbits=$(echo "scale=1; $rxbytes*8/1000"|bc 2>/dev/null) rxkbspeed=$rxkbits rxkbspeedunit="Kb/s" if float_cond $rxkbspeed '>=' 1000; then rxkbspeed=$(echo "scale=2; $rxkbits/1000"|bc 2>/dev/null) rxkbspeedunit="Mb/s" if float_cond $rxkbspeed '>=' 1000; then rxkbspeed=$(echo "scale=3; $rxkbits/1000000"|bc 2>/dev/null) rxkbspeedunit="Gb/s" fi fi rxkbytes=$(echo "scale=1; $rxbytes/1024"|bc 2>/dev/null) rxkBspeed=$rxkbytes rxkBspeedunit="KiB/s" if float_cond $rxkBspeed '>=' 1024; then rxkBspeed=$(echo "scale=2; $rxkbytes/1024"|bc 2>/dev/null) rxkBspeedunit="MiB/s" if float_cond $rxkBspeed '>=' 1024; then rxkBspeed=$(echo "scale=3; $rxkbytes/1048576"|bc 2>/dev/null) rxkBspeedunit="GiB/s" fi fi txpackets=$(echo "scale=2; ($txpackets0-$txpackets1)/$rr"|bc 2>/dev/null) txbytes=$(echo "scale=2; ($txbytes0-$txbytes1)/$rr"|bc 2>/dev/null) if float_cond $txpackets '>' 0; then avgtxsz=$(echo "scale=2; $txbytes/$txpackets"|bc 2>/dev/null) else avgtxsz=0 fi txkbits=$(echo "scale=1; $txbytes*8/1000"|bc 2>/dev/null) txkbspeed=$txkbits txkbspeedunit="Kb/s" if float_cond $txkbspeed '>=' 1000; then txkbspeed=$(echo "scale=2; $txkbits/1000"|bc 2>/dev/null) txkbspeedunit="Mb/s" if float_cond $txkbspeed '>=' 1000; then txkbspeed=$(echo "scale=3; $txkbits/1000000"|bc 2>/dev/null) txkbspeedunit="Gb/s" fi fi txkbytes=$(echo "scale=1; $txbytes/1024"|bc 2>/dev/null) txkBspeed=$txkbytes txkBspeedunit="KiB/s" if float_cond $txkBspeed '>=' 1024; then txkBspeed=$(echo "scale=2; $txkbytes/1024"|bc 2>/dev/null) txkBspeedunit="MiB/s" if float_cond $txkBspeed '>=' 1024; then txkBspeed=$(echo "scale=3; $txkbytes/1048576"|bc 2>/dev/null) txkBspeedunit="GiB/s" fi fi if [ $oneshot = "true" ];then message="displayed only once" oneshot="false" else clear echo "Real time statistics for $iface ($message)" echo "" ifconfig $iface 2>/dev/null|grep $iface|sed 's/^'$iface'[ ]\+//' ifconfig $iface 2>/dev/null|grep -v $iface|sed 's/^\s*//'|sed 's/ Kb)/KiB)/g'|sed 's/ Mb)/MiB)/g'|sed 's/ Gb)/GiB)/g'|sed 's/ Tb)/TiB)/g'|sed 's/ KB)/KiB)/g'|sed 's/ MB)/MiB)/g'|sed 's/ GB)/GiB)/g'|sed 's/ TB)/TiB)/g' echo "RX packets per second:_$rxpackets$pkts"|awk -F"_" '{printf("%-23s %-1s \n", $1, $2)}' echo "RX average packet size:_$avgrxsz$bytes"|awk -F"_" '{printf("%-23s %-1s \n", $1, $2)}' echo "RX throughput:_$rxkbspeed$rxkbspeedunit ($rxkBspeed$rxkBspeedunit)"|awk -F"_" '{printf("%-23s %-1s \n", $1, $2)}' echo "" echo "TX packets per second:_$txpackets$pkts"|awk -F"_" '{printf("%-23s %-1s \n", $1, $2)}' echo "TX average packet size:_$avgtxsz$bytes"|awk -F"_" '{printf("%-23s %-1s \n", $1, $2)}' echo "TX throughput:_$txkbspeed$txkbspeedunit ($txkBspeed$txkBspeedunit)"|awk -F"_" '{printf("%-23s %-1s \n", $1, $2)}' if [ $oneshot = "false" ];then exit 0; fi fi date1=$(date +%s.%N) offset=$(echo "scale=6; $date1-$date0"|bc 2>/dev/null) sleeptime=$(echo "scale=6; $rr-($offset*1.15)"|bc 2>/dev/null) if float_cond $sleeptime '<=' 0; then sleeptime=0.001 echo "WARNING: Results are not accurate due to too high system load." fi sleep $sleeptime 2> /dev/null done
|
Message édité par maxxximatoze le 21-12-2009 à 15:32:51
|