1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-11 04:20:05 +02:00
copilot/docker/api/bin/sensors.sh

45 lines
1.1 KiB
Bash
Raw Normal View History

2017-06-23 19:24:25 +03:00
#!/bin/bash
set -e
help() {
echo 'Uses cli tools free and top to determine current CPU and memory usage'
echo 'for the telemetry service.'
}
# memory usage in percent
memory() {
# awk oneliner to get memory usage
# free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
# output:
# Memory Usage: 15804/15959MB (99.03%)
local memory=$(free -m | awk 'NR==2{printf "%.2f", $3*100/$2 }')
/bin/containerpilot -putmetric "api_memory_percent=$memory"
2017-06-23 19:24:25 +03:00
}
# cpu load
cpu() {
# oneliner to display cpu load
# top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'
local cpuload=$(uptime | awk '{printf "%.2f", $6}')
/bin/containerpilot -putmetric "api_cpu_load=$cpuload"
2017-06-23 19:24:25 +03:00
}
diskusage() {
local usage=$(df -P | grep '/$' | awk 'NR=2{print $3}' | sed 's/[^0-9\.]*//g')
/bin/containerpilot -putmetric "api_disk_usage=$usage"
2017-06-23 19:24:25 +03:00
}
diskcapacity() {
local capacity=$(df -P | grep '/$' | awk 'NR=2{print $2}' | sed 's/[^0-9\.]*//g')
/bin/containerpilot -putmetric "api_disk_capacity=$capacity"
2017-06-23 19:24:25 +03:00
}
cmd=$1
if [ ! -z "$cmd" ]; then
shift 1
$cmd "$@"
exit
fi
help