Add disk usage check for Kuma pushes
This commit is contained in:
parent
1f59cb6a36
commit
e8d06c2374
2 changed files with 43 additions and 0 deletions
|
@ -27,5 +27,12 @@
|
|||
"type": "mount",
|
||||
"target": "/mnt/media",
|
||||
"push": "xxxxxxxxxxxxxxxx"
|
||||
},
|
||||
{
|
||||
"name": "root_disk",
|
||||
"type": "disk",
|
||||
"target": "vda5",
|
||||
"threshold": 85,
|
||||
"push": "xxxxxxxxxxxxxxxx"
|
||||
}
|
||||
]
|
||||
|
|
36
kuma-push.sh
36
kuma-push.sh
|
@ -32,6 +32,40 @@ check_http() { # arg: URL
|
|||
check_service() { systemctl is-active --quiet "$1" && echo "up 0" || echo "down 0"; }
|
||||
check_docker() { docker inspect -f '{{.State.Running}}' "$1" &>/dev/null && echo "up 0" || echo "down 0"; }
|
||||
check_mount() { mountpoint -q "$1" 2>/dev/null && echo "up 0" || echo "down 0"; }
|
||||
check_disk() {
|
||||
# args: device (e.g. sda, /dev/vda5) and threshold percentage
|
||||
local raw_target="$1" threshold="$2" dev mount usage
|
||||
|
||||
if [[ -z "$threshold" || ! "$threshold" =~ ^[0-9]+$ ]]; then
|
||||
echo "down 0"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$raw_target" == /dev/* ]]; then
|
||||
dev="$raw_target"
|
||||
else
|
||||
dev="/dev/$raw_target"
|
||||
fi
|
||||
|
||||
if ! mount=$(findmnt -nr -S "$dev" -o TARGET 2>/dev/null); then
|
||||
echo "down 0"
|
||||
return 0
|
||||
fi
|
||||
|
||||
usage=$(df --output=pcent "$mount" 2>/dev/null | awk 'NR==2 {gsub(/%/, ""); print $1}') || true
|
||||
|
||||
if [[ -z "$usage" ]]; then
|
||||
echo "down 0"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if (( usage >= threshold )); then
|
||||
echo "down $usage"
|
||||
else
|
||||
echo "up $usage"
|
||||
fi
|
||||
}
|
||||
|
||||
check_native() { echo "up 0"; }
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
@ -41,12 +75,14 @@ jq -c '.[]' "$CFG" | while IFS= read -r item; do
|
|||
type=$(jq -r '.type' <<<"$item")
|
||||
id=$(jq -r '.push' <<<"$item")
|
||||
tgt=$(jq -r '.target // empty' <<<"$item") # target may be absent
|
||||
thr=$(jq -r '.threshold // empty' <<<"$item")
|
||||
|
||||
case "$type" in
|
||||
http) read -r stat ping < <(check_http "$tgt") ;;
|
||||
service) read -r stat ping < <(check_service "$tgt") ;;
|
||||
docker) read -r stat ping < <(check_docker "$tgt") ;;
|
||||
mount) read -r stat ping < <(check_mount "$tgt") ;;
|
||||
disk) read -r stat ping < <(check_disk "$tgt" "$thr") ;;
|
||||
native) read -r stat ping < <(check_native) ;;
|
||||
*) stat=down ping=0 ;;
|
||||
esac
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue