Managing Hetzner Cloud (Deep Dive)
Deep-dive Hetzner Cloud management using the hcloud CLI for detailed analysis.
MANDATORY: Discovery-First Pattern
Always discover available resources before performing analysis.
Phase 1: Discovery
#!/bin/bash
echo "=== Server Types (Available) ==="
hcloud server-type list -o columns=id,name,description,cores,memory,disk,storage_type 2>/dev/null | head -20
echo ""
echo "=== Placement Groups ==="
hcloud placement-group list -o columns=id,name,type,servers 2>/dev/null | head -10
echo ""
echo "=== Primary IPs ==="
hcloud primary-ip list -o columns=id,name,type,ip,datacenter,assignee_id,auto_delete 2>/dev/null | head -10
echo ""
echo "=== Certificates ==="
hcloud certificate list -o columns=id,name,type,domain_names,not_valid_after 2>/dev/null | head -10
echo ""
echo "=== Images ==="
hcloud image list --type system -o columns=id,name,description,os_flavor,os_version,disk_size 2>/dev/null | head -15
echo ""
echo "=== Snapshots ==="
hcloud image list --type snapshot -o columns=id,description,created,image_size,disk_size 2>/dev/null | head -10
echo ""
echo "=== Backups ==="
hcloud image list --type backup -o columns=id,description,created,image_size,created_from_name 2>/dev/null | head -10
Phase 2: Analysis
#!/bin/bash
SERVER_ID="${1:?Server ID required}"
echo "=== Server Details ==="
hcloud server describe "$SERVER_ID" -o json 2>/dev/null | jq '{
id, name, status,
server_type: .server_type.name,
cores: .server_type.cores,
memory: .server_type.memory,
disk: .server_type.disk,
datacenter: .datacenter.name,
location: .datacenter.location.city,
public_ipv4: .public_net.ipv4.ip,
public_ipv6: .public_net.ipv6.ip,
private_nets: [.private_net[] | {network: .network, ip: .ip}],
image: .image.name,
iso: .iso,
rescue_enabled: .rescue_enabled,
locked: .locked,
protection: .protection,
labels: .labels,
created: .created
}'
echo ""
echo "=== Server Metrics (CPU last 1h) ==="
hcloud server metrics "$SERVER_ID" --type cpu --start "$(date -u -v-1H +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)" --end "$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o json 2>/dev/null | jq '.metrics.timeseries[] | {name: .labels.mode, values: [.values[-5:][]]}' | head -20
echo ""
echo "=== Server Metrics (Disk I/O last 1h) ==="
hcloud server metrics "$SERVER_ID" --type disk --start "$(date -u -v-1H +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)" --end "$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o json 2>/dev/null | jq '.metrics.timeseries[] | {name: .labels | to_entries | map(.value) | join("-"), values_tail: [.values[-3:][]]}' | head -15
echo ""
echo "=== Server Metrics (Network last 1h) ==="
hcloud server metrics "$SERVER_ID" --type network --start "$(date -u -v-1H +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)" --end "$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o json 2>/dev/null | jq '.metrics.timeseries[] | {name: .labels | to_entries | map(.value) | join("-"), values_tail: [.values[-3:][]]}' | head -15
Output Format
ID NAME STATUS TYPE CORES MEMORY DATACENTER IP
123456 web-01 running cx21 2 4GB fsn1-dc14 1.2.3.4
Safety Rules
- Use read-only commands:
list, describe, metrics
- Never run
delete, shutdown, rebuild without explicit user confirmation
- Use
-o json with jq for detailed output, -o columns= for summaries
- Limit output with
| head -N to stay under 50 lines
Anti-Hallucination Rules
- NEVER assume resource names — always discover via CLI/API in Phase 1 before referencing in Phase 2.
- NEVER fabricate metric names or dimensions — verify against the service documentation or
--help output.
- NEVER mix CLI commands between service versions — confirm which version/API you are targeting.
- ALWAYS use the discovery → verify → analyze chain — every resource referenced must have been discovered first.
- ALWAYS handle empty results gracefully — an empty response is valid data, not an error to retry.
Counter-Rationalizations
| Shortcut |
Counter |
Why |
| "I'll skip discovery and check known resources" |
Always run Phase 1 discovery first |
Resource names change, new resources appear — assumed names cause errors |
| "The user only asked for a quick check" |
Follow the full discovery → analysis flow |
Quick checks miss critical issues; structured analysis catches silent failures |
| "Default configuration is probably fine" |
Audit configuration explicitly |
Defaults often leave logging, security, and optimization features disabled |
| "Metrics aren't needed for this" |
Always check relevant metrics when available |
API/CLI responses show current state; metrics reveal trends and intermittent issues |
| "I don't have access to that" |
Try the command and report the actual error |
Assumed permission failures prevent useful investigation; actual errors are informative |
1---2name: managing-hetzner-cloud3description: Use when working with Hetzner Cloud — hetzner Cloud deep-dive management via the hcloud CLI. Covers server types, pricing, placement groups, certificates, primary IPs, and detailed server metrics. Use for detailed Hetzner Cloud analysis beyond basic server listing.4---56# Managing Hetzner Cloud (Deep Dive)78Deep-dive Hetzner Cloud management using the `hcloud` CLI for detailed analysis.910## MANDATORY: Discovery-First Pattern1112**Always discover available resources before performing analysis.**1314### Phase 1: Discovery1516```bash17#!/bin/bash1819echo "=== Server Types (Available) ==="20hcloud server-type list -o columns=id,name,description,cores,memory,disk,storage_type 2>/dev/null | head -202122echo ""23echo "=== Placement Groups ==="24hcloud placement-group list -o columns=id,name,type,servers 2>/dev/null | head -102526echo ""27echo "=== Primary IPs ==="28hcloud primary-ip list -o columns=id,name,type,ip,datacenter,assignee_id,auto_delete 2>/dev/null | head -102930echo ""31echo "=== Certificates ==="32hcloud certificate list -o columns=id,name,type,domain_names,not_valid_after 2>/dev/null | head -103334echo ""35echo "=== Images ==="36hcloud image list --type system -o columns=id,name,description,os_flavor,os_version,disk_size 2>/dev/null | head -153738echo ""39echo "=== Snapshots ==="40hcloud image list --type snapshot -o columns=id,description,created,image_size,disk_size 2>/dev/null | head -104142echo ""43echo "=== Backups ==="44hcloud image list --type backup -o columns=id,description,created,image_size,created_from_name 2>/dev/null | head -1045```4647### Phase 2: Analysis4849```bash50#!/bin/bash5152SERVER_ID="${1:?Server ID required}"5354echo "=== Server Details ==="55hcloud server describe "$SERVER_ID" -o json 2>/dev/null | jq '{56 id, name, status,57 server_type: .server_type.name,58 cores: .server_type.cores,59 memory: .server_type.memory,60 disk: .server_type.disk,61 datacenter: .datacenter.name,62 location: .datacenter.location.city,63 public_ipv4: .public_net.ipv4.ip,64 public_ipv6: .public_net.ipv6.ip,65 private_nets: [.private_net[] | {network: .network, ip: .ip}],66 image: .image.name,67 iso: .iso,68 rescue_enabled: .rescue_enabled,69 locked: .locked,70 protection: .protection,71 labels: .labels,72 created: .created73}'7475echo ""76echo "=== Server Metrics (CPU last 1h) ==="77hcloud server metrics "$SERVER_ID" --type cpu --start "$(date -u -v-1H +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)" --end "$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o json 2>/dev/null | jq '.metrics.timeseries[] | {name: .labels.mode, values: [.values[-5:][]]}' | head -207879echo ""80echo "=== Server Metrics (Disk I/O last 1h) ==="81hcloud server metrics "$SERVER_ID" --type disk --start "$(date -u -v-1H +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)" --end "$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o json 2>/dev/null | jq '.metrics.timeseries[] | {name: .labels | to_entries | map(.value) | join("-"), values_tail: [.values[-3:][]]}' | head -158283echo ""84echo "=== Server Metrics (Network last 1h) ==="85hcloud server metrics "$SERVER_ID" --type network --start "$(date -u -v-1H +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)" --end "$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o json 2>/dev/null | jq '.metrics.timeseries[] | {name: .labels | to_entries | map(.value) | join("-"), values_tail: [.values[-3:][]]}' | head -1586```8788## Output Format8990```91ID NAME STATUS TYPE CORES MEMORY DATACENTER IP92123456 web-01 running cx21 2 4GB fsn1-dc14 1.2.3.493```9495## Safety Rules96- Use read-only commands: `list`, `describe`, `metrics`97- Never run `delete`, `shutdown`, `rebuild` without explicit user confirmation98- Use `-o json` with jq for detailed output, `-o columns=` for summaries99- Limit output with `| head -N` to stay under 50 lines100101## Anti-Hallucination Rules1021031. **NEVER assume resource names** — always discover via CLI/API in Phase 1 before referencing in Phase 2.1042. **NEVER fabricate metric names or dimensions** — verify against the service documentation or `--help` output.1053. **NEVER mix CLI commands between service versions** — confirm which version/API you are targeting.1064. **ALWAYS use the discovery → verify → analyze chain** — every resource referenced must have been discovered first.1075. **ALWAYS handle empty results gracefully** — an empty response is valid data, not an error to retry.108109## Counter-Rationalizations110111| Shortcut | Counter | Why |112|----------|---------|-----|113| "I'll skip discovery and check known resources" | Always run Phase 1 discovery first | Resource names change, new resources appear — assumed names cause errors |114| "The user only asked for a quick check" | Follow the full discovery → analysis flow | Quick checks miss critical issues; structured analysis catches silent failures |115| "Default configuration is probably fine" | Audit configuration explicitly | Defaults often leave logging, security, and optimization features disabled |116| "Metrics aren't needed for this" | Always check relevant metrics when available | API/CLI responses show current state; metrics reveal trends and intermittent issues |117| "I don't have access to that" | Try the command and report the actual error | Assumed permission failures prevent useful investigation; actual errors are informative |118