mirror of
https://github.com/pstadler/metrics.sh.git
synced 2025-02-28 13:59:12 -05:00
implement network_io metric. get rid of broken subshells
This commit is contained in:
parent
bd037022ad
commit
916cabc8ec
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
collect () {
|
collect () {
|
||||||
echo $(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 () {
|
docs () {
|
||||||
|
31
metrics/disk_io.sh
Normal file
31
metrics/disk_io.sh
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# #!/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 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
|
||||||
|
|
||||||
|
# init () {
|
||||||
|
# mkfifo ./foobar
|
||||||
|
# #exec 3<> ./foobar
|
||||||
|
# __disk_io_bgproc > ./foobar &
|
||||||
|
# }
|
||||||
|
|
||||||
|
# collect () {
|
||||||
|
# cat ./foobar
|
||||||
|
# }
|
@ -9,8 +9,8 @@ if [ -z $DISK_USAGE_MOUNTPOINT ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
collect () {
|
collect () {
|
||||||
echo $(df | awk -v disk_regexp="^$DISK_USAGE_MOUNTPOINT" \
|
report $(df | awk -v disk_regexp="^$DISK_USAGE_MOUNTPOINT" \
|
||||||
'$0 ~ disk_regexp {printf "%.1f", $5}')
|
'$0 ~ disk_regexp {printf "%.1f", $5}')
|
||||||
}
|
}
|
||||||
|
|
||||||
docs () {
|
docs () {
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if is_osx; then
|
if is_osx; then
|
||||||
|
|
||||||
declare -r __memory_os_memsize=$(sysctl -n hw.memsize)
|
declare -r __memory_os_memsize=$(sysctl -n hw.memsize)
|
||||||
|
|
||||||
collect () {
|
collect () {
|
||||||
echo $(vm_stat | awk -v total_memory=$__memory_os_memsize \
|
report $(vm_stat | awk -v total_memory=$__memory_os_memsize \
|
||||||
'BEGIN {FS=" *"; pages=0}
|
'BEGIN {FS=" *"; pages=0}
|
||||||
/Pages (free|inactive|speculative)/ {pages+=$2}
|
/Pages (free|inactive|speculative)/ {pages+=$2}
|
||||||
END {printf "%.1f", 100 - (pages * 4096) / total_memory * 100.0}')
|
END {printf "%.1f", 100 - (pages * 4096) / total_memory * 100.0}')
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
collect () {
|
collect () {
|
||||||
echo $(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
|
fi
|
||||||
|
|
||||||
docs () {
|
docs () {
|
||||||
|
41
metrics/network_io.sh
Normal file
41
metrics/network_io.sh
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ -z $NETWORK_IO_INTERFACE ]; then
|
||||||
|
if is_osx; then
|
||||||
|
NETWORK_IO_INTERFACE="en0"
|
||||||
|
else
|
||||||
|
NETWORK_IO_INTERFACE="eth0"
|
||||||
|
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}'
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_osx; then
|
||||||
|
__network_io_collect () {
|
||||||
|
netstat -bI $NETWORK_IO_INTERFACE | \
|
||||||
|
awk "/$NETWORK_IO_INTERFACE/"'{print $7" "$10; exit}'
|
||||||
|
}
|
||||||
|
else
|
||||||
|
__network_io_collect () {
|
||||||
|
echo TODO
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
collect () {
|
||||||
|
local sample=( $(__network_io_collect) )
|
||||||
|
if [ ${__network_io_sample[0]} -ne 0 ]; 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
|
||||||
|
__network_io_sample=( "${sample[@]}" )
|
||||||
|
}
|
||||||
|
|
||||||
|
docs () {
|
||||||
|
echo "Network traffic in kB/s."
|
||||||
|
}
|
@ -1,17 +1,13 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if is_osx; then
|
if is_osx; then
|
||||||
|
|
||||||
collect () {
|
collect () {
|
||||||
echo $(sysctl -n vm.swapusage | awk '{printf "%.1f", $6 / $3 * 100.0}')
|
report $(sysctl -n vm.swapusage | awk '{printf "%.1f", $6 / $3 * 100.0}')
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
collect () {
|
collect () {
|
||||||
echo $(free | awk '/Swap/{printf "%.1f", $3/$2 * 100.0}')
|
report $(free | awk '/Swap/{printf "%.1f", $3/$2 * 100.0}')
|
||||||
}
|
}
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docs () {
|
docs () {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# config
|
# config
|
||||||
INTERVAL=2
|
INTERVAL=1
|
||||||
REPORTER=stdout
|
REPORTER=stdout
|
||||||
|
|
||||||
#init
|
#init
|
||||||
@ -63,9 +63,23 @@ while true; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
result=$(__m_${metric}_collect)
|
report () {
|
||||||
__r_${REPORTER}_report $metric $result
|
local result
|
||||||
|
if [ -z $2 ]; then
|
||||||
|
label=$metric
|
||||||
|
result="$1"
|
||||||
|
else
|
||||||
|
label="$metric.$1"
|
||||||
|
result="$2"
|
||||||
|
fi
|
||||||
|
__r_${REPORTER}_report $label $result
|
||||||
|
}
|
||||||
|
|
||||||
|
__m_${metric}_collect
|
||||||
done
|
done
|
||||||
|
|
||||||
sleep $INTERVAL
|
sleep $INTERVAL
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# trap 'kill $(jobs -pr)' SIGINT SIGTERM EXIT
|
||||||
|
# trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
|
Loading…
x
Reference in New Issue
Block a user