mirror of
https://github.com/pstadler/metrics.sh.git
synced 2025-11-06 20:33:04 -05:00
structured main routines. implement file reporter
This commit is contained in:
@@ -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 () {
|
||||
|
||||
@@ -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" \
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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
9
metrics/ping.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
collect () {
|
||||
report 1
|
||||
}
|
||||
|
||||
docs () {
|
||||
echo "Send a simple ping in form of an integer '1'."
|
||||
}
|
||||
Reference in New Issue
Block a user