improved coding standards. options parsing. verbose logging

This commit is contained in:
Patrick Stadler
2015-03-11 22:02:00 +01:00
parent 9858beb329
commit 5c65c6646f
10 changed files with 115 additions and 39 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/sh
collect () {
report $(ps aux | awk '{sum+=$3} END {printf "%.1f\n", sum}' | tail -n 1)
report $(ps aux | awk '{ sum+=$3 } END { printf "%.1f\n", sum }' | tail -n 1)
}
docs () {

View File

@@ -8,7 +8,7 @@ init () {
DISK_IO_MOUNTPOINT="/dev/vda"
fi
fi
readonly __disk_io_fifo=$__TEMP_DIR/disk_io
readonly __disk_io_fifo=$TEMP_DIR/disk_io
mkfifo $__disk_io_fifo
__disk_io_bgproc &
}
@@ -16,7 +16,7 @@ init () {
if is_osx; then
__disk_io_bgproc () {
iostat -K -d -w $INTERVAL $DISK_IO_MOUNTPOINT | while read line; do
echo $line | awk '{print $3}' > $__disk_io_fifo
echo $line | awk '{ print $3 }' > $__disk_io_fifo
done
}
else
@@ -26,11 +26,11 @@ else
fi
collect () {
report $(cat $__disk_io_fifo)
report $(cat < $__disk_io_fifo)
}
terminate () {
if [ ! -z $__disk_io_fifo ] && [ -f $__disk_io_fifo ]; then
if [ ! -z $__disk_io_fifo ] && [ -p $__disk_io_fifo ]; then
rm $__disk_io_fifo
fi
}

View File

@@ -12,7 +12,7 @@ init () {
collect () {
report $(df | awk -v disk_regexp="^$DISK_USAGE_MOUNTPOINT" \
'$0 ~ disk_regexp {printf "%.1f", $5}')
'$0 ~ disk_regexp { printf "%.1f", $5 }')
}
docs () {

View File

@@ -7,13 +7,14 @@ if is_osx; then
collect () {
report $(vm_stat | awk -v total_memory=$__memory_os_memsize \
'BEGIN {FS=" *"; pages=0}
/Pages (free|inactive|speculative)/ {pages+=$2}
END {printf "%.1f", 100 - (pages * 4096) / total_memory * 100.0}')
'BEGIN { FS=" *"; pages=0 }
/Pages (free|inactive|speculative)/ { pages+=$2 }
END { printf "%.1f", 100 - (pages * 4096) / total_memory * 100.0 }')
}
else
collect () {
report $(free | awk '/buffers\/cache/{printf "%.1f", 100 - $4 / ($3 + $4) * 100.0}')
report $(free | awk '/buffers\/cache/
{ printf "%.1f", 100 - $4 / ($3 + $4) * 100.0 }')
}
fi

View File

@@ -13,19 +13,19 @@ init () {
if is_osx; then
__network_io_collect () {
netstat -bI $NETWORK_IO_INTERFACE | \
awk "/$NETWORK_IO_INTERFACE/"'{print $7" "$10; exit}'
netstat -bI $NETWORK_IO_INTERFACE |
awk "/$NETWORK_IO_INTERFACE/"'{ print $7" "$10 }'
}
else
__network_io_collect () {
cat /proc/net/dev | awk -v iface_regex="$NETWORK_IO_INTERFACE:" \
'$0 ~ iface_regex {print $2" "$10}'
'$0 ~ iface_regex { print $2" "$10 }'
}
fi
__network_io_calc_kBps() {
echo $1 $2 | awk -v divisor=$__network_io_divisor \
'{printf "%.2f", ($1 - $2) / divisor}'
'{ printf "%.2f", ($1 - $2) / divisor }'
}
collect () {

View File

@@ -2,11 +2,12 @@
if is_osx; then
collect () {
report $(sysctl -n vm.swapusage | awk '{printf "%.1f", $6 / $3 * 100.0}')
report $(sysctl -n vm.swapusage |
awk '{ if ($3 == 0) exit; printf "%.1f", $6 / $3 * 100.0 }')
}
else
collect () {
report $(free | awk '/Swap/{printf "%.1f", $3/$2 * 100.0}')
report $(free | awk '/Swap/{ printf "%.1f", $3/$2 * 100.0 }')
}
fi