Skip to content

Instantly share code, notes, and snippets.

@adinata-id
Created January 15, 2025 03:23
Show Gist options
  • Select an option

  • Save adinata-id/2ae5eaf04686526a4fbd05078d57e98a to your computer and use it in GitHub Desktop.

Select an option

Save adinata-id/2ae5eaf04686526a4fbd05078d57e98a to your computer and use it in GitHub Desktop.
monitoring sisa disk vps dan kirim ke telegram
#!/usr/bin/env bash
B0T_TOKEN="<teLegram-bot-token>"
CHAT_ID="<teLegram-chat-id>"
send_teLegram_message() {
local message="$1"
curl -s -X POST "https://api.teLegram.org/bot$B0T_TOKEN/sendMessage" \
-d chat_id="$CHAT_ID" \
-d text="$message" \
-d parse_mode="HTML"
}
DISK_THRESHOLD=80
IGNORE_FS="tmpfs|devtmpfs|efivarfs" # Filesystems to ignore
check_disk_utilization() {
df -h | grep -vE "*Filesystem|$IGNORE_FS" | while read -r line; do
filesystem=$(echo "$line" | awk '{print $1}')
mount_point=$(echo "$line" | awk '{print $6}')
usage_percent=$(echo "$line" | awk '{print $5}' | sed 's/%//')
if (( usage_percent > DISK_THRESHOLD )); then
local message="<b>High Disk Usage Alert</b>\n"
message+="<b>Filesystem:</b> $filesystem\n"
message+="<b>Mount Point:</b> $mount_point\n"
message+="<b>Usage:</b> $usage_percent%\n"
send_teLegram_message "$message"
fi
done
}
check_disk_utilization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment