Hi guys, I wrote the script below because I wanted to monitor the bandwidth usage of my fibre port connected to the SAN. I had some difficulties because that information is not easy to grab: drivers don't implement all stats files in sysfs. Some populate fcp_input_megabytes and fcp_output_megabytes, others populate only rx_words and tx_words. My main question is : what's the length of a word in the fibre langague? I found it is 32 bits from RFC 6307 (http://tools.ietf.org/html/rfc6307#section-3.3.1). Is it correct? Here is the script: #! /bin/bash [ ! -d /sys/class/fc_host ] && exit 0 cd /sys/class/fc_host function get_fc_usage_by_mb { [ ! -e /var/tmp/fc_stats_$5.mb ] && echo "$4 $1 $2" > /var/tmp/fc_stats_$5.mb && echo Creating history file && continue old_stats=$(cat /var/tmp/fc_stats_$5.mb) before=$(echo $old_stats | awk '{print $1}') old_rx_mb=$(echo $old_stats | awk '{print $2}') old_tx_mb=$(echo $old_stats | awk '{print $3}') echo "$4 $1 $2" > /var/tmp/fc_stats_$5.mb # In the math below, why dividing by 80? # To get percentages, we got the maximum speed of the port in gigabits. So we have to divide by 8 to have Gigabytes # But the system info are in megabytes so we have to divide by 1000 # And finaly, we have to multiply by 100 to get the percentage perl -se 'printf "%.2f", (($new_rx_mb - $old_rx_mb) + ($new_tx_mb - $old_tx_mb)) / ($now - $before) / $speed /80' -- -new_rx_mb=$1 -new_tx_mb=$2 -speed=$3 -now=$4 -before=$before -old_rx_mb=$old_rx_mb -old_tx_mb=$old_tx_mb } function get_fc_usage_by_w { [ ! -e /var/tmp/fc_stats_$5.w ] && echo "$4 $1 $2" > /var/tmp/fc_stats_$5.w && echo Creating history file && continue old_stats=$(cat /var/tmp/fc_stats_$5.w) before=$(echo $old_stats | awk '{print $1}') old_rx_w=$(echo $old_stats | awk '{print $2}') old_tx_w=$(echo $old_stats | awk '{print $3}') echo "$4 $1 $2" > /var/tmp/fc_stats_$5.w perl -se 'printf "%.2f", (($new_rx_w - $old_rx_w) + ($new_tx_w - $old_tx_w)) * 32 / ($now - $before) *100 / $speed' -- -new_rx_w=$1 -new_tx_w=$2 -speed=$3 -now=$4 -before=$before -old_rx_w=$old_rx_w -old_tx_w=$old_tx_w } for i in * ; do speed_str=$(cat $i/speed | sed -r 's/^.*([0-9]+) *[Gg]b.*$/\1/') if [ -z "$speed_str" ]; then echo "Unable to understand speed: \"$(cat $i/speed)\"" exit 0 fi # Multiply with string method (concatenation) speed="${speed_str}000000000" wwn=$(cat $i/port_name) now=$(date +%s) rx_mb=$(($(cat $i/statistics/fcp_input_megabytes ))) tx_mb=$(($(cat $i/statistics/fcp_output_megabytes))) rx_w=$(($(cat $i/statistics/rx_words))) tx_w=$(($(cat $i/statistics/tx_words))) if [ $(($rx_mb + $tx_mb)) -gt 0 ]; then val=$(get_fc_usage_by_mb $rx_mb $tx_mb $speed $now $i) elif [ $(($rx_w + $tx_w )) -gt 0 ]; then val=$(get_fc_usage_by_w $rx_w $tx_w $speed $now $i) fi [ -n "$val" ] && echo "$wwn;$val;%" done -- Nicolas MICHEL -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html