-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcluster_notes.sh
More file actions
71 lines (55 loc) · 2.32 KB
/
cluster_notes.sh
File metadata and controls
71 lines (55 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Set temp file
TEMP_FILE="/tmp/datacenter_notes.txt"
TIMESTAMP=$(date '+%a %b %d %I:%M:%S %p %Z %Y')
# Begin raw (human-readable) content
RAW=$(mktemp)
cat <<EOF > "$RAW"
## 🏢 Proxmox Cluster: \`Datacenter\`
_"One ring to monitor them all."_ 🧙♂️🖥️
---
EOF
# Get Proxmox node names
NODES=$(pvesh get /nodes --output-format=json | jq -r '.[].node')
# Loop over nodes
for NODE in $NODES; do
echo "Collecting info from node: $NODE"
INFO=$(ssh -o ConnectTimeout=5 root@$NODE '
HOST=$(hostname)
KERNEL=$(uname -r)
UPTIME=$(uptime -p)
CPU=$(grep -m1 "model name" /proc/cpuinfo | cut -d: -f2 | xargs)
CORES=$(nproc)
MEM=$(free -h | awk "/Mem:/ {print \$3 \" / \" \$2}")
DISK=$(df -h / | awk "NR==2 {print \$2 \" total, \" \$4 \" free\"}")
IPADDR=$(hostname -I | awk "{print \$1}")
GPUS=$(lspci | grep -i VGA | grep -v "ASPEED\|Matrox" || echo "None")
echo -e "### 🖥️ Node: \`$HOST\`\n- **Kernel**: \`$KERNEL\`\n- **Uptime**: ⏱ $UPTIME"
echo -e "- **CPU**: 🔥 $CPU\n- **Cores**: $CORES\n- **Memory**: 🧠 $MEM"
echo -e "- **Root Disk**: 💽 $DISK\n- **IP**: 🌐 $IPADDR"
echo -e "- **GPU**: 🎮 ${GPUS:-None}"
echo -e "\n#### 📦 Containers"
pct list | awk "NR>1 && \$2 == \"running\" {printf \"- 📦 %s (ID: %s) — running\\n\", \$3, \$1}" || echo "- None"
echo -e "\n#### 🖥️ VMs"
qm list | awk "NR>1 && \$3 == \"running\" {printf \"- 🖥️ %s (ID: %s) — running\\n\", \$3, \$1}" || echo "- None"
echo -e "\n---"
' 2>/dev/null)
if [ -n "$INFO" ]; then
echo "$INFO" >> "$RAW"
else
echo -e "### 🖥️ Node: \`$NODE\`\n- ❌ Unable to connect or retrieve data\n---" >> "$RAW"
fi
done
# Footer
echo -e "### 📝 Notes\n- ⏱️ Updated automatically via cron\n- 📅 Last updated: $TIMESTAMP" >> "$RAW"
# Encode content for Proxmox Notes Panel (URL-encoded + comment-prefixed)
{
while IFS= read -r LINE; do
# URL-encode line and prefix with "#"
echo "#$(jq -sRr @uri <<< "$LINE")"
done < "$RAW"
} > "$TEMP_FILE"
# Append to /etc/pve/datacenter.cfg
cat "$TEMP_FILE" > /etc/pve/datacenter.cfg
# Clean up
rm -f "$RAW" "$TEMP_FILE"