Skip to content

Instantly share code, notes, and snippets.

@Lucifer1590
Created May 20, 2025 08:32
Show Gist options
  • Save Lucifer1590/6e8575c4b4e13fa2799f7ebf99e4ee35 to your computer and use it in GitHub Desktop.
Save Lucifer1590/6e8575c4b4e13fa2799f7ebf99e4ee35 to your computer and use it in GitHub Desktop.
A SCRIPT TO GET node metrics in discord webhook
#!/bin/bash
IP="xxx.xxx.xxx.xxx"
WEBHOOK_URL="https://discord.com/api/webhooks/"
while true; do
health=$(curl -sk https://$IP/health)
state=$(curl -sk https://$IP/state)
metrics=$(curl -sk https://$IP/metrics)
# Health
health_status=$(echo "$health" | jq -r '.status // "N/A"')
mem_cache_items=$(echo "$health" | jq -r '.memory_cache.items')
mem_cache_hits=$(echo "$health" | jq -r '.memory_cache.hits')
mem_cache_misses=$(echo "$health" | jq -r '.memory_cache.misses')
disk_cache_items=$(echo "$health" | jq -r '.disk_cache.items')
disk_cache_hits=$(echo "$health" | jq -r '.disk_cache.hits')
disk_cache_misses=$(echo "$health" | jq -r '.disk_cache.misses')
# State
pop_id=$(echo "$state" | jq -r '.pop_id')
pop_name=$(echo "$state" | jq -r '.pop_name')
pop_location=$(echo "$state" | jq -r '.pop_location')
identity_id=$(echo "$state" | jq -r '.identity_id')
registered=$(echo "$state" | jq -r '.identity_registered')
hw_signature=$(echo "$state" | jq -r '.hardware_signature')
rewards_enabled=$(echo "$state" | jq -r '.rewards_payment.rewards_enabled')
solana_pubkey=$(echo "$state" | jq -r '.rewards_payment.solana_pubkey')
server_host=$(echo "$state" | jq -r '.server.host')
server_port=$(echo "$state" | jq -r '.server.port')
server_workers=$(echo "$state" | jq -r '.server.workers')
cache_mem_size=$(echo "$state" | jq -r '.cache_config.memory_cache_size_mb')
cache_disk_size=$(echo "$state" | jq -r '.cache_config.disk_cache_size_gb')
cache_ttl=$(echo "$state" | jq -r '.cache_config.default_ttl_seconds')
respect_origin_headers=$(echo "$state" | jq -r '.cache_config.respect_origin_headers')
max_cacheable_mb=$(echo "$state" | jq -r '.cache_config.max_cacheable_size_mb')
api_base_url=$(echo "$state" | jq -r '.api_endpoints.base_url')
# Metrics available?
metrics_available=$(echo "$metrics" | jq -e 'select(.requests != {} or .bandwidth != {} or .cache_hit_ratio != {} or .origin_errors != {})' >/dev/null && echo "Yes" || echo "No")
message=$(cat <<EOF
\`\`\`
πŸ–₯ VPS STATUS REPORT @ $(date '+%Y-%m-%d %H:%M:%S')
πŸ“ POP Name : $pop_name
πŸ“Œ POP ID : $pop_id
πŸ“ Location : $pop_location
πŸ†” Identity ID : $identity_id
βœ… Registered : $registered
🧬 HW Signature : ${hw_signature:0:10}...
πŸ”‘ Solana Pubkey : ${solana_pubkey:0:12}...
πŸ’Έ Rewards Enabled: $rewards_enabled
🚦 Health : $health_status
🧠 Mem Cache : $mem_cache_items items | $mem_cache_hits hits / $mem_cache_misses misses
πŸ’Ύ Disk Cache : $disk_cache_items items | $disk_cache_hits hits / $disk_cache_misses misses
πŸ“Š Cache Config
β”œβ”€ Memory Size : ${cache_mem_size} MB
β”œβ”€ Disk Size : ${cache_disk_size} GB
β”œβ”€ Default TTL : ${cache_ttl} sec
β”œβ”€ Max Object Size : ${max_cacheable_mb} MB
└─ Respect Origin : $respect_origin_headers
πŸ”Œ Server
β”œβ”€ Host : $server_host
β”œβ”€ Port : $server_port
└─ Workers : $server_workers
🌐 API Base URL : $api_base_url
πŸ“ˆ Metrics Available : $metrics_available
\`\`\`
EOF
)
# Show on terminal COMMENT THIS IF YOU DONT WANT IT TO SHOW ON TERMINAL
echo "$message"
# Send to Discord
jq -n --arg content "$message" '{content: $content}' | \
curl -s -H "Content-Type: application/json" -d @- "$WEBHOOK_URL" > /dev/null
# CHANGE THE TIME IF YOU WANT MORE FLEXIBILITY ITS IN SEC
sleep 20
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment