implement disk_io metric on osx

This commit is contained in:
Patrick Stadler 2015-03-08 17:51:15 +01:00
parent 9312c27c9c
commit c54c9d73b7
4 changed files with 77 additions and 35 deletions

14
README.md Normal file
View File

@ -0,0 +1,14 @@
## TODO
- [] README
- [] option parsing
- [] allow multiple reporters
- [] implement log reporter
- [] better docs, including reporters (--docs)
- [] config file support
- [] config file auto-generation
- [] disk_io metric
- [] load custom metrics
- [] async metrics
- [] extended metric labels?
- [] same metric multiple times (e.g. disk_usage for multiple devices)

View File

@ -13,3 +13,12 @@ is_osx () { [ $OS_TYPE == 'osx' ]; }
is_linux () { [ $OS_TYPE == 'solaris' ]; }
is_bsd () { [ $OS_TYPE == 'bsd']; }
is_unknown () { [ $OS_TYPE == 'unknown' ]; }
make_temp_dir () {
if is_osx; then
mktemp -d -t 'sysmetrics'
else
mktemp -d
fi
}

View File

@ -1,31 +1,41 @@
# #!/bin/sh
#!/bin/sh
# if [ -z $DISK_IO_MOUNTPOINT ]; then
# if is_osx; then
# DISK_IO_MOUNTPOINT="disk0"
# else
# DISK_IO_MOUNTPOINT="/dev/vda"
# fi
# fi
if [ -z $DISK_IO_MOUNTPOINT ]; then
if is_osx; then
DISK_IO_MOUNTPOINT="disk0"
else
DISK_IO_MOUNTPOINT="/dev/vda"
fi
fi
# if is_osx; then
# __disk_io_bgproc () {
# iostat -K -d -c 99999 -w $INTERVAL $DISK_IO_MOUNTPOINT | while read line; do
# echo $line | awk '{print $3}' > ./foobar
# done
# }
# else
# __disk_io_bgproc () {
# echo $(iostat -y -d 1 $DISK_IO_MOUNTPOINT)
# }
# fi
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
done
}
else
__disk_io_bgproc () {
echo $(iostat -y -d 1 $DISK_IO_MOUNTPOINT)
}
fi
# init () {
# mkfifo ./foobar
# #exec 3<> ./foobar
# __disk_io_bgproc > ./foobar &
# }
__disk_io_fifo=$__TEMP_DIR/disk_io
# collect () {
# cat ./foobar
# }
init () {
__disk_io_bgproc &
mkfifo $__disk_io_fifo
}
collect () {
report $(cat $__disk_io_fifo)
}
terminate () {
rm $__disk_io_fifo
}
docs () {
echo "Disk I/O in MB/s."
echo "\$DISK_IO_MOUNTPOINT=$DISK_IO_MOUNTPOINT"
}

View File

@ -4,12 +4,24 @@
INTERVAL=1
REPORTER=stdout
#init
__METRICS=()
# load utils
for util in ./lib/utils/*.sh; do source $util; done
# init
__METRICS=()
__TEMP_DIR=$(make_temp_dir)
# register trap
trap '
for metric in ${__METRICS[@]}; do
if ! is_function __m_${metric}_terminate; then
continue
fi
__m_${metric}_terminate
done
trap - SIGTERM && kill -- -$$ SIGINT SIGTERM EXIT
' SIGINT SIGTERM EXIT
# load reporter
source ./reporters/${REPORTER}.sh
copy_function init __r_${REPORTER}_init
@ -80,6 +92,3 @@ while true; do
sleep $INTERVAL
done
# trap 'kill $(jobs -pr)' SIGINT SIGTERM EXIT
# trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT