structured main routines. implement file reporter

This commit is contained in:
Patrick Stadler
2015-03-08 20:37:56 +01:00
parent c54c9d73b7
commit 9858beb329
12 changed files with 213 additions and 138 deletions

View File

@@ -1,12 +1,17 @@
#!/bin/sh
if [ -z $DISK_IO_MOUNTPOINT ]; then
if is_osx; then
DISK_IO_MOUNTPOINT="disk0"
else
DISK_IO_MOUNTPOINT="/dev/vda"
init () {
if [ -z $DISK_IO_MOUNTPOINT ]; then
if is_osx; then
DISK_IO_MOUNTPOINT="disk0"
else
DISK_IO_MOUNTPOINT="/dev/vda"
fi
fi
fi
readonly __disk_io_fifo=$__TEMP_DIR/disk_io
mkfifo $__disk_io_fifo
__disk_io_bgproc &
}
if is_osx; then
__disk_io_bgproc () {
@@ -20,19 +25,14 @@ else
}
fi
__disk_io_fifo=$__TEMP_DIR/disk_io
init () {
__disk_io_bgproc &
mkfifo $__disk_io_fifo
}
collect () {
report $(cat $__disk_io_fifo)
}
terminate () {
rm $__disk_io_fifo
if [ ! -z $__disk_io_fifo ] && [ -f $__disk_io_fifo ]; then
rm $__disk_io_fifo
fi
}
docs () {

View File

@@ -1,12 +1,14 @@
#!/bin/sh
if [ -z $DISK_USAGE_MOUNTPOINT ]; then
if is_osx; then
DISK_USAGE_MOUNTPOINT="/dev/disk1"
else
DISK_USAGE_MOUNTPOINT="/dev/vda"
init () {
if [ -z $DISK_USAGE_MOUNTPOINT ]; then
if is_osx; then
DISK_USAGE_MOUNTPOINT="/dev/disk1"
else
DISK_USAGE_MOUNTPOINT="/dev/vda"
fi
fi
fi
}
collect () {
report $(df | awk -v disk_regexp="^$DISK_USAGE_MOUNTPOINT" \

View File

@@ -1,7 +1,9 @@
#!/bin/sh
if is_osx; then
declare -r __memory_os_memsize=$(sysctl -n hw.memsize)
init () {
readonly __memory_os_memsize=$(sysctl -n hw.memsize)
}
collect () {
report $(vm_stat | awk -v total_memory=$__memory_os_memsize \

View File

@@ -1,19 +1,14 @@
#!/bin/sh
if [ -z $NETWORK_IO_INTERFACE ]; then
if is_osx; then
NETWORK_IO_INTERFACE="en0"
else
NETWORK_IO_INTERFACE="eth0"
init () {
if [ -z $NETWORK_IO_INTERFACE ]; then
if is_osx; then
NETWORK_IO_INTERFACE="en0"
else
NETWORK_IO_INTERFACE="eth0"
fi
fi
fi
declare -r __network_io_divisor=$[$INTERVAL * 1024]
__network_io_sample=(0 0)
__network_io_calc_kBps() {
echo $1 $2 | awk -v divisor=$__network_io_divisor \
'{printf "%.2f", ($1 - $2) / divisor}'
readonly __network_io_divisor=$[$INTERVAL * 1024]
}
if is_osx; then
@@ -28,9 +23,14 @@ else
}
fi
__network_io_calc_kBps() {
echo $1 $2 | awk -v divisor=$__network_io_divisor \
'{printf "%.2f", ($1 - $2) / divisor}'
}
collect () {
local sample=( $(__network_io_collect) )
if [ ${__network_io_sample[0]} -ne 0 ]; then
if [ ! -z $__network_io_sample ]; then
report "in" $(__network_io_calc_kBps ${sample[0]} ${__network_io_sample[0]})
report "out" $(__network_io_calc_kBps ${sample[1]} ${__network_io_sample[1]})
fi

9
metrics/ping.sh Normal file
View File

@@ -0,0 +1,9 @@
#!/bin/sh
collect () {
report 1
}
docs () {
echo "Send a simple ping in form of an integer '1'."
}