Diagnostics & Log Analysis
Diagnostics & Log Analysis
Section titled “Diagnostics & Log Analysis”This guide covers diagnostic commands, log analysis techniques, and debugging approaches for Bifrost Proxy.
Diagnostic Commands
Section titled “Diagnostic Commands”Health Checks
Section titled “Health Checks”# Quick health checkcurl -s http://localhost:7082/api/v1/health | jq# Response: {"status":"healthy","time":"2024-01-15T10:30:00Z"}
# Detailed statuscurl -s http://localhost:7082/api/v1/status | jq
# Backend healthcurl -s http://localhost:7082/api/v1/backends | jq '.[] | {name, type, healthy}'Connection Statistics
Section titled “Connection Statistics”# Overall statisticscurl -s http://localhost:7082/api/v1/stats | jq
# Active connectionscurl -s http://localhost:7082/api/v1/stats | jq '.active_connections'
# Recent requests (if logging enabled)curl -s http://localhost:7082/api/v1/requests | jq '.[-10:]'
# Requests by statuscurl -s http://localhost:7082/api/v1/requests | jq 'group_by(.status) | map({status: .[0].status, count: length})'Backend Diagnostics
Section titled “Backend Diagnostics”# All backends with statscurl -s http://localhost:7082/api/v1/backends | jq
# Specific backendcurl -s http://localhost:7082/api/v1/backends | jq '.[] | select(.name=="my-backend")'
# Backend latencycurl -s http://localhost:7082/api/v1/backends | jq '.[] | {name, avg_latency_ms: .stats.avg_latency_ms}'
# Unhealthy backendscurl -s http://localhost:7082/api/v1/backends | jq '.[] | select(.healthy==false)'Network Diagnostics
Section titled “Network Diagnostics”# Test proxy connectivitycurl -x http://localhost:7080 https://httpbin.org/ip -v
# Test with timingcurl -x http://localhost:7080 https://httpbin.org/ip -o /dev/null -s -w \ "DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\nTotal: %{time_total}s\n"
# Test SOCKS5curl --socks5 localhost:7180 https://httpbin.org/ip -v
# Check what ports are listeningnetstat -tlnp | grep bifrostss -tlnp | grep bifrost
# Check open connectionslsof -i -P -n | grep bifrostCache Diagnostics
Section titled “Cache Diagnostics”# Cache statisticscurl -s http://localhost:7082/api/v1/cache/stats | jq
# Cache hit ratecurl -s http://localhost:7082/api/v1/cache/stats | jq '{ hit_rate: (.hits / (.hits + .misses) * 100), hits: .hits, misses: .misses}'
# Clear cachecurl -X DELETE http://localhost:7082/api/v1/cacheVPN/Tunnel Diagnostics
Section titled “VPN/Tunnel Diagnostics”# VPN statuscurl -s http://localhost:7082/api/v1/vpn/status | jq
# VPN connectionscurl -s http://localhost:7082/api/v1/vpn/connections | jq
# Split tunnel rulescurl -s http://localhost:7082/api/v1/vpn/split/rules | jq
# WireGuard interface (if kernel mode)sudo wg show
# Network interface statusip addr show bifrost0Mesh Network Diagnostics
Section titled “Mesh Network Diagnostics”# Mesh statuscurl -s http://localhost:7082/api/v1/mesh/status | jq
# Peer listcurl -s http://localhost:7082/api/v1/mesh/networks/my-network/peers | jq
# P2P connectionscurl -s http://localhost:7082/api/v1/p2p/connections | jq
# NAT type detectioncurl -s http://localhost:7082/api/v1/p2p/nat | jq
# Routescurl -s http://localhost:7082/api/v1/mesh/routes | jqLog Analysis
Section titled “Log Analysis”Viewing Logs
Section titled “Viewing Logs”# Systemd service logsjournalctl -u bifrost-server -f
# Last 100 linesjournalctl -u bifrost-server -n 100 --no-pager
# Since specific timejournalctl -u bifrost-server --since "1 hour ago"
# Docker container logsdocker logs bifrost-server -fdocker logs bifrost-server --tail 100
# File-based logstail -f /var/log/bifrost/server.log
# Multiple log filestail -f /var/log/bifrost/*.logEnabling Debug Logging
Section titled “Enabling Debug Logging”# config.yamllogging: level: debug format: text # Human-readable for debuggingOr via CLI:
bifrost-server -c config.yaml --log-level debugFiltering Logs
Section titled “Filtering Logs”# Filter by log leveljournalctl -u bifrost-server | grep -E "error|ERROR"journalctl -u bifrost-server | grep -i warn
# Filter by componentjournalctl -u bifrost-server | grep -i backendjournalctl -u bifrost-server | grep -i authjournalctl -u bifrost-server | grep -i wireguard
# Filter by requestjournalctl -u bifrost-server | grep "example.com"
# Filter by IPjournalctl -u bifrost-server | grep "192.168.1.100"JSON Log Analysis
Section titled “JSON Log Analysis”When using JSON log format:
logging: level: info format: jsonParse with jq:
# All errorscat /var/log/bifrost/server.log | jq 'select(.level == "error")'
# Errors in last hourcat /var/log/bifrost/server.log | jq 'select(.level == "error" and .time > (now - 3600))'
# Group by error messagecat /var/log/bifrost/server.log | jq 'select(.level == "error") | .msg' | sort | uniq -c | sort -rn
# Requests to specific domaincat /var/log/bifrost/server.log | jq 'select(.msg | contains("example.com"))'
# Slow requests (if request time is logged)cat /var/log/bifrost/server.log | jq 'select(.duration_ms > 1000)'
# Authentication failurescat /var/log/bifrost/server.log | jq 'select(.msg | contains("auth") and .level == "error")'Log Aggregation
Section titled “Log Aggregation”Loki + Grafana
Section titled “Loki + Grafana”# docker-compose.ymlservices: loki: image: grafana/loki:2.9.0 ports: - "3100:3100"
bifrost-server: logging: driver: loki options: loki-url: "http://localhost:3100/loki/api/v1/push" labels: "app=bifrost,service=server"Query in Grafana:
{app="bifrost"} |= "error"{app="bifrost"} | json | level="error"{app="bifrost"} | json | duration_ms > 1000Elasticsearch
Section titled “Elasticsearch”Use Filebeat to ship logs:
# filebeat.ymlfilebeat.inputs: - type: container paths: - '/var/lib/docker/containers/*/*.log' json.keys_under_root: true json.message_key: msg
output.elasticsearch: hosts: ["elasticsearch:9200"] index: "bifrost-%{+yyyy.MM.dd}"Prometheus Metrics
Section titled “Prometheus Metrics”Accessing Metrics
Section titled “Accessing Metrics”# All metricscurl -s http://localhost:7090/metrics
# Specific metricscurl -s http://localhost:7090/metrics | grep bifrost_connectionscurl -s http://localhost:7090/metrics | grep bifrost_requestscurl -s http://localhost:7090/metrics | grep bifrost_backendKey Metrics to Monitor
Section titled “Key Metrics to Monitor”# Active connectionscurl -s http://localhost:7090/metrics | grep bifrost_connections_active
# Request ratecurl -s http://localhost:7090/metrics | grep bifrost_requests_total
# Error ratecurl -s http://localhost:7090/metrics | grep bifrost_connections_errors_total
# Backend healthcurl -s http://localhost:7090/metrics | grep bifrost_backend_healthy
# Backend latencycurl -s http://localhost:7090/metrics | grep bifrost_backend_latency_seconds
# Memory usagecurl -s http://localhost:7090/metrics | grep bifrost_memory_bytes
# Goroutine countcurl -s http://localhost:7090/metrics | grep bifrost_goroutines
# Cache statisticscurl -s http://localhost:7090/metrics | grep bifrost_cachePrometheus Queries
Section titled “Prometheus Queries”# Request rate per secondrate(bifrost_requests_total[5m])
# Error rate percentagerate(bifrost_connections_errors_total[5m]) / rate(bifrost_connections_total[5m]) * 100
# Average request durationrate(bifrost_request_duration_seconds_sum[5m]) / rate(bifrost_request_duration_seconds_count[5m])
# P95 latencyhistogram_quantile(0.95, rate(bifrost_request_duration_seconds_bucket[5m]))
# Unhealthy backendsbifrost_backend_healthy == 0
# Backend latency comparisonbifrost_backend_latency_seconds{quantile="0.99"}Debugging Techniques
Section titled “Debugging Techniques”Request Tracing
Section titled “Request Tracing”Enable request logging:
api: enable_request_log: true request_log_size: 1000View recent requests:
# All recent requestscurl -s http://localhost:7082/api/v1/requests | jq
# Failed requestscurl -s http://localhost:7082/api/v1/requests | jq '.[] | select(.status >= 400)'
# Slow requestscurl -s http://localhost:7082/api/v1/requests | jq '.[] | select(.duration_ms > 1000)'
# Requests to specific domaincurl -s http://localhost:7082/api/v1/requests | jq '.[] | select(.host | contains("example.com"))'Network Packet Capture
Section titled “Network Packet Capture”# Capture proxy trafficsudo tcpdump -i any port 7080 -w proxy-traffic.pcap
# Capture with filterssudo tcpdump -i any port 7080 and host 192.168.1.100 -w filtered.pcap
# Live viewsudo tcpdump -i any port 7080 -A
# Capture WireGuard trafficsudo tcpdump -i any udp port 51820 -w wireguard.pcap
# Analyze with Wiresharkwireshark proxy-traffic.pcapProcess Debugging
Section titled “Process Debugging”# Check process statusps aux | grep bifrost
# Memory mappmap $(pgrep bifrost-server)
# Open fileslsof -p $(pgrep bifrost-server)
# Network connectionslsof -i -P -n | grep bifrost
# System calls (Linux)strace -p $(pgrep bifrost-server) -f
# CPU profiling (if pprof enabled)go tool pprof http://localhost:7091/debug/pprof/profile
# Memory profilinggo tool pprof http://localhost:7091/debug/pprof/heapConfiguration Validation
Section titled “Configuration Validation”# Validate configurationbifrost-server validate -c config.yaml
# Check YAML syntaxyamllint config.yaml
# Dump parsed configurationbifrost-server dump-config -c config.yamlCommon Log Messages
Section titled “Common Log Messages”Informational
Section titled “Informational”| Message | Meaning |
|---|---|
server starting | Service is starting |
listening on :7080 | HTTP proxy ready |
backend connected | Backend is online |
config reloaded | Hot reload completed |
Warnings
Section titled “Warnings”| Message | Meaning | Action |
|---|---|---|
backend unhealthy | Backend failed health check | Check backend connectivity |
rate limit exceeded | Client hit rate limit | Adjust limits or client behavior |
connection pool exhausted | Too many connections | Increase pool size |
slow response | Backend response slow | Investigate backend |
Errors
Section titled “Errors”| Message | Meaning | Action |
|---|---|---|
connection refused | Cannot connect to backend | Check backend is running |
authentication failed | Invalid credentials | Verify credentials |
certificate error | TLS issue | Check certificates |
timeout | Operation took too long | Increase timeout or check network |
Troubleshooting Scripts
Section titled “Troubleshooting Scripts”Health Check Script
Section titled “Health Check Script”#!/bin/bash# health-check.sh
echo "=== Bifrost Health Check ==="
echo -e "\n--- Service Status ---"systemctl is-active bifrost-server
echo -e "\n--- Health Endpoint ---"curl -s http://localhost:7082/api/v1/health | jq
echo -e "\n--- Backend Status ---"curl -s http://localhost:7082/api/v1/backends | jq '.[] | {name, healthy}'
echo -e "\n--- Active Connections ---"curl -s http://localhost:7082/api/v1/stats | jq '.active_connections'
echo -e "\n--- Recent Errors ---"journalctl -u bifrost-server --since "5 minutes ago" | grep -i error | tail -5
echo -e "\n--- Resource Usage ---"ps aux | grep bifrost | grep -v grep | awk '{print "CPU:", $3"%, MEM:", $4"%, RSS:", $6/1024"MB"}'Diagnostic Report Script
Section titled “Diagnostic Report Script”#!/bin/bash# diagnostic-report.sh
OUTPUT="bifrost-diagnostic-$(date +%Y%m%d-%H%M%S).txt"
{ echo "=== Bifrost Diagnostic Report ===" echo "Generated: $(date)" echo ""
echo "=== System Info ===" uname -a echo ""
echo "=== Bifrost Version ===" bifrost-server version 2>/dev/null || echo "Not found in PATH" echo ""
echo "=== Service Status ===" systemctl status bifrost-server --no-pager 2>/dev/null || echo "Not a systemd service" echo ""
echo "=== Health Check ===" curl -s http://localhost:7082/api/v1/health 2>/dev/null | jq . || echo "API not reachable" echo ""
echo "=== Backend Status ===" curl -s http://localhost:7082/api/v1/backends 2>/dev/null | jq . || echo "API not reachable" echo ""
echo "=== Statistics ===" curl -s http://localhost:7082/api/v1/stats 2>/dev/null | jq . || echo "API not reachable" echo ""
echo "=== Recent Logs (last 50 lines) ===" journalctl -u bifrost-server -n 50 --no-pager 2>/dev/null || echo "No systemd logs" echo ""
echo "=== Network Listeners ===" netstat -tlnp 2>/dev/null | grep bifrost || ss -tlnp | grep bifrost echo ""
echo "=== Resource Usage ===" ps aux | grep bifrost | grep -v grep echo ""
echo "=== Open Files ===" lsof -p $(pgrep bifrost-server) 2>/dev/null | wc -l echo ""
} > "$OUTPUT"
echo "Diagnostic report saved to: $OUTPUT"Monitor Script
Section titled “Monitor Script”#!/bin/bash# monitor.sh - Real-time monitoring
while true; do clear echo "=== Bifrost Monitor ($(date)) ==="
echo -e "\n--- Health ---" curl -s http://localhost:7082/api/v1/health | jq -r '.status'
echo -e "\n--- Connections ---" curl -s http://localhost:7082/api/v1/stats | jq '.active_connections'
echo -e "\n--- Backend Health ---" curl -s http://localhost:7082/api/v1/backends | jq -r '.[] | "\(.name): \(.healthy)"'
echo -e "\n--- Resource Usage ---" ps aux | grep bifrost | grep -v grep | awk '{print "CPU:", $3"%, MEM:", $4"%"}'
sleep 5done