Tools Diagnostik

Tools Diagnostik #

Mengetahui tools yang tepat untuk setiap situasi bisa mengubah troubleshooting dari proses yang melelahkan menjadi diagnosis yang sistematis dan efisien. Berikut adalah arsenal tools yang wajib dikuasai setiap operator Caddy.

curl — Swiss Army Knife HTTP #

curl adalah tool paling sering digunakan untuk testing dan debugging HTTP:

# Request dasar dengan verbose output
curl -v https://example.com

# Hanya tampilkan headers response
curl -I https://example.com

# Cek status code saja
curl -o /dev/null -s -w "%{http_code}\n" https://example.com

# Timing detail (time_connect, time_starttransfer, time_total)
curl -o /dev/null -s -w "
DNS:          %{time_namelookup}s
Connect:      %{time_connect}s
TLS:          %{time_appconnect}s
TTFB:         %{time_starttransfer}s
Total:        %{time_total}s
Size:         %{size_download} bytes
HTTP Status:  %{http_code}
" https://example.com

# Test dengan custom headers
curl -H "Authorization: Bearer token123" \
     -H "Content-Type: application/json" \
     -H "X-Custom: value" \
     https://api.example.com/endpoint

# POST request
curl -X POST https://api.example.com/data \
     -H "Content-Type: application/json" \
     -d '{"key": "value"}'

# Follow redirects dan lihat chain
curl -L -v https://www.example.com 2>&1 | grep -E "< HTTP|Location:"

# Test dari IP berbeda (simulasi)
curl --interface eth1 https://example.com

# Test dengan specific TLS version
curl --tlsv1.3 https://example.com
curl --tlsv1.2 https://example.com

# Download dengan progress bar
curl -# -o output.html https://example.com/large-page.html

# Ignore SSL certificate errors (testing only!)
curl -k https://localhost:8443/

openssl — TLS/SSL Diagnostik #

# Cek sertifikat server
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | \
    openssl x509 -noout -text

# Info singkat sertifikat
echo | openssl s_client -connect example.com:443 2>/dev/null | \
    openssl x509 -noout -subject -issuer -dates

# Cek sertifikat chain
echo | openssl s_client -connect example.com:443 -showcerts 2>/dev/null | \
    grep -E "subject=|issuer="

# Cek cipher suite yang digunakan
openssl s_client -connect example.com:443 -brief 2>/dev/null | head -5

# Test apakah TLS 1.3 didukung
openssl s_client -connect example.com:443 -tls1_3 2>&1 | head -5

# Verifikasi sertifikat secara manual
openssl verify -CAfile /etc/ssl/certs/ca-certificates.crt /path/to/cert.pem

# Decode CSR atau sertifikat
openssl x509 -in /path/to/cert.pem -noout -text
openssl req -in /path/to/csr.pem -noout -text

# Cek kapan sertifikat expire
echo | openssl s_client -connect example.com:443 2>/dev/null | \
    openssl x509 -noout -enddate
# notAfter=Jan 15 12:00:00 2025 GMT

dig / nslookup — DNS Diagnostik #

# Lookup A record
dig example.com A +short

# Lookup AAAA (IPv6)
dig example.com AAAA +short

# Cek semua record
dig example.com ANY

# Trace DNS resolution step by step
dig example.com +trace

# Query server DNS tertentu
dig @8.8.8.8 example.com A

# Cek TXT record (untuk DNS challenge verification)
dig _acme-challenge.example.com TXT

# Cek NS record (nameserver)
dig example.com NS

# Reverse lookup (IP → hostname)
dig -x 203.0.113.1

# Cek propagasi DNS ke multiple server
for dns in 8.8.8.8 1.1.1.1 9.9.9.9; do
    echo -n "DNS $dns: "
    dig @$dns example.com A +short
done

ss / netstat — Network Connections #

# Cek port yang sedang listen
sudo ss -tlnp
# -t TCP, -l listening, -n numeric, -p process

# Filter port tertentu
sudo ss -tlnp | grep -E ':80|:443|:2019'

# Lihat semua koneksi ke Caddy
sudo ss -tnp | grep caddy

# Hitung koneksi aktif
sudo ss -tnp | grep caddy | wc -l

# Lihat koneksi per state (ESTABLISHED, TIME_WAIT, dll)
sudo ss -tan | awk '{print $1}' | sort | uniq -c | sort -rn

# Lihat koneksi dari IP tertentu
sudo ss -tnp | grep "203.0.113"

# Cek apakah port bisa diakses
nc -zv example.com 443
nc -zv localhost 3000

journalctl — System Logs #

# Lihat log Caddy real-time
sudo journalctl -u caddy -f

# Log sejak caddy distart terakhir
sudo journalctl -u caddy -b

# Log 1 jam terakhir
sudo journalctl -u caddy --since "1 hour ago"

# Log dengan timestamp yang mudah dibaca
sudo journalctl -u caddy --since "2024-01-15 14:00" --until "2024-01-15 15:00"

# Hanya error dan warning
sudo journalctl -u caddy -p err..warning

# Filter dengan grep
sudo journalctl -u caddy | grep -i "tls\|certificate\|error"

# Export log untuk analisis
sudo journalctl -u caddy --since "today" -o json > /tmp/caddy-logs.json

# Cek berapa kali Caddy restart
sudo journalctl -u caddy | grep "Started Caddy"

tcpdump — Network Packet Capture #

# Capture traffic ke/dari port 443
sudo tcpdump -i eth0 port 443 -n

# Capture dan simpan ke file untuk analisis
sudo tcpdump -i any port 80 or port 443 -w /tmp/capture.pcap

# Lihat isi HTTP request (port 80, plaintext)
sudo tcpdump -i eth0 port 80 -A | grep -E "GET|POST|Host:|HTTP"

# Capture hanya dari IP tertentu
sudo tcpdump -i eth0 src 203.0.113.1

# Batasi jumlah packet
sudo tcpdump -i eth0 port 443 -c 100

# Baca file capture
sudo tcpdump -r /tmp/capture.pcap | head -20

Caddy Admin API sebagai Diagnostic Tool #

# Status keseluruhan
curl -s http://localhost:2019/config/ | jq '{
    apps: (.apps | keys),
    servers: (.apps.http.servers | keys),
    tls_automation: (.apps.tls.automation.policies | length)
}'

# Monitor upstreams secara real-time
watch -n 5 'curl -s http://localhost:2019/reverse_proxy/upstreams/ | \
    jq -r ".[] | \"\(.address): \(if .healthy then \"UP\" else \"DOWN\" end) (req: \(.num_requests), fails: \(.fails))\""'

# Info TLS certificates
curl -s http://localhost:2019/pki/ca/local | jq '{
    name: .name,
    root_expires: .root.not_after
}'

# Cek konfigurasi routes aktif
curl -s http://localhost:2019/config/apps/http/servers/srv0/routes/ | \
    jq '[.[] | {
        id: .["@id"],
        hosts: (.match[0].host // ["*"]),
        handler: .handle[0].handler
    }]'

wrk / ab — Load Testing #

# wrk: load testing modern
# Install: sudo apt install wrk
wrk -t4 -c100 -d30s https://example.com/

# Output:
# Running 30s test @ https://example.com/
#   4 threads and 100 connections
#   Thread Stats   Avg      Stdev     Max   +/- Stdev
#     Latency    10.12ms   2.34ms  50.12ms   90.12%
#     Req/Sec     2.45k   123.45    3.21k    80.00%
#   293455 requests in 30.10s, 512.34MB read
# Requests/sec:   9751.00
# Transfer/sec:    17.02MB

# Apache Benchmark (ab)
ab -n 1000 -c 100 https://example.com/

# Cek performa dengan gzip vs tanpa gzip
ab -n 1000 -c 10 -H "Accept-Encoding: gzip" https://example.com/
ab -n 1000 -c 10 https://example.com/

mtr — Network Path Analysis #

# Trace network path dengan statistik loss/latency
mtr example.com

# Output non-interaktif (berguna untuk logging)
mtr --report --report-cycles 10 example.com

# Cek apakah ada packet loss ke server
mtr --report --no-dns --report-cycles 20 203.0.113.1

Ringkasan #

  • curl -v adalah titik mulai untuk hampir semua debugging HTTP — verbose output menampilkan semua headers dan SSL/TLS info.
  • curl -o /dev/null -s -w "%{time_*}" memberikan breakdown timing yang detail — gunakan untuk mengidentifikasi bottleneck (DNS, connect, TLS, TTFB).
  • openssl s_client -connect untuk inspeksi sertifikat dan cipher suite — lebih detail dari curl.
  • dig +trace sangat berguna untuk debugging DNS yang lambat atau tidak propagasi dengan benar.
  • Admin API Caddy (/reverse_proxy/upstreams/) adalah cara paling cepat untuk melihat status upstream real-time.
  • wrk untuk load testing sederhana — jalankan sebelum dan sesudah perubahan konfigurasi untuk memastikan tidak ada regresi performa.

← Sebelumnya: Caddy Validate   Berikutnya: Best Practices →


httpie — Alternatif curl yang Lebih User-Friendly #

# Install
sudo apt install httpie  # atau: pip install httpie

# GET request dengan tampilan yang lebih mudah dibaca
http https://api.example.com/users

# POST dengan JSON (tidak perlu header Content-Type manual)
http POST https://api.example.com/users \
    name="Alice" \
    email="[email protected]"

# Dengan authentication
http --auth alice:password https://example.com/admin/

# Lihat hanya headers
http --headers https://example.com/

# Verbose (mirip curl -v tapi lebih readable)
http --verbose https://example.com/

Grafana + Loki untuk Log Visualization #

# docker-compose.yml untuk log stack lokal
services:
  loki:
    image: grafana/loki:latest
    ports:
      - "3100:3100"
    command: -config.file=/etc/loki/local-config.yaml
  
  promtail:
    image: grafana/promtail:latest
    volumes:
      - /var/log/caddy:/var/log/caddy:ro
      - ./promtail-config.yml:/etc/promtail/config.yml
  
  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"
# promtail-config.yml
scrape_configs:
  - job_name: caddy
    static_configs:
      - targets: [localhost]
        labels:
          job: caddy
          __path__: /var/log/caddy/*.log
    pipeline_stages:
      - json:
          expressions:
            status: status
            duration: duration
            method: request.method
            uri: request.uri
      - labels:
          status:
          method:

Dengan setup ini, semua log Caddy bisa di-query dan divisualisasikan di Grafana — sangat berguna untuk analisis traffic dan troubleshooting masalah yang sulit direproduksi.

About | Author | Content Scope | Editorial Policy | Privacy Policy | Disclaimer | Contact