code cleaup. add disk_usage reporter. add handling for docs(). various tweaks and fixes

This commit is contained in:
Patrick Stadler
2015-02-22 20:45:57 +01:00
parent 8957cb4387
commit bd037022ad
9 changed files with 114 additions and 44 deletions

View File

@@ -1,5 +1,9 @@
#!/bin/sh
collect () {
echo $(ps aux | awk {'sum+=$3;print sum'} | tail -n 1)
echo $(ps aux | awk '{sum+=$3} END {printf "%.1f\n", sum}' | tail -n 1)
}
docs () {
echo "CPU load percentage."
}

19
metrics/disk_usage.sh Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/sh
if [ -z $DISK_USAGE_MOUNTPOINT ]; then
if is_osx; then
DISK_USAGE_MOUNTPOINT="/dev/disk1"
else
DISK_USAGE_MOUNTPOINT="/dev/vda"
fi
fi
collect () {
echo $(df | awk -v disk_regexp="^$DISK_USAGE_MOUNTPOINT" \
'$0 ~ disk_regexp {printf "%.1f", $5}')
}
docs () {
echo "Disk usage percentage for a file system at a given mount point."
echo "\$DISK_USAGE_MOUNTPOINT=$DISK_USAGE_MOUNTPOINT"
}

View File

@@ -1,21 +1,24 @@
#!/bin/sh
if [ $OS_TYPE == "osx" ]; then
if is_osx; then
# FIXME: total_memory leaks out
total_memory=$(sysctl -n hw.memsize)
declare -r __memory_os_memsize=$(sysctl -n hw.memsize)
collect () {
echo $(vm_stat | awk -v total_memory=$total_memory \
'BEGIN {FS=" *"; pages=0}
/Pages (free|inactive|speculative)/ {pages+=$2}
END {printf "%.2f", 100 - (pages * 4096) / total_memory * 100.0}')
echo $(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}')
}
else
collect () {
echo $(free | awk '/buffers\/cache/{printf "%.2f", $4 / ($3 + $4) * 100.0}')
echo $(free | awk '/buffers\/cache/{printf "%.1f", 100 - $4 / ($3 + $4) * 100.0}')
}
fi
fi
docs () {
echo "Percentage of used memory."
}

View File

@@ -1,15 +1,19 @@
#!/bin/sh
if [ $OS_TYPE == "osx" ]; then
if is_osx; then
collect () {
echo $(sysctl -n vm.swapusage | awk '{printf "%.2f", $6 / $3 * 100.0}')
echo $(sysctl -n vm.swapusage | awk '{printf "%.1f", $6 / $3 * 100.0}')
}
else
collect () {
echo $(free | awk '/Swap/{printf "%.2f", $3/$2 * 100.0;}')
echo $(free | awk '/Swap/{printf "%.1f", $3/$2 * 100.0}')
}
fi
fi
docs () {
echo "Percentage of used swap space."
}