Created
May 20, 2025 08:32
-
-
Save Lucifer1590/6e8575c4b4e13fa2799f7ebf99e4ee35 to your computer and use it in GitHub Desktop.
A SCRIPT TO GET node metrics in discord webhook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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