How to Monitor Traffic Passing Through FastProxy: Built‑in Observability Guide

FastProxy provides built‑in traffic monitoring through structured request logging, Go pprof runtime profiling, and graceful shutdown metrics without requiring external instrumentation.

The kingson4wu/fast_proxy repository ships with a complete observability stack that lets you watch every HTTP request, inspect resource usage, and diagnose performance bottlenecks in real time. Whether you are running the proxy in production or debugging locally, you can monitor traffic passing through FastProxy by leveraging its zap‑based logger and the standard Go net/http/pprof endpoints.

Structured Request Logging

Every HTTP request that enters FastProxy is captured by the central proxy handler and emitted as structured JSON logs.

In outproxy/outproxy.go, the requestProxy function receives incoming traffic and delegates to the concrete proxy implementation via proxy.GetProxy. Each proxy implementation uses the shared zap logger located in common/logger/zap to write log entries that include:

  • HTTP method and full URL
  • Response status code
  • Latency in milliseconds
  • Client IP address
{
  "level": "info",
  "msg": "handle request",
  "method": "GET",
  "url": "http://example.com/api",
  "status": 200,
  "latency_ms": 12,
  "client_ip": "192.168.1.42",
  "time": "2026-03-05T12:34:56Z"
}

The logger writes to stdout by default, allowing you to pipe output to a file or forward it to a log aggregation service.

Runtime Performance Profiling with pprof

FastProxy exposes the standard Go pprof profiling endpoints under /debug/pprof, enabling you to capture CPU, memory, and goroutine snapshots while the proxy is running.

The registration happens in two places:

  1. outproxy/outproxy.go imports _ "net/http/pprof" to ensure the pprof handlers are registered.
  2. common/server/server.go wires the /debug/pprof path into the HTTP router (or Fast‑HTTP adaptor when running in Fast‑HTTP mode).

Available endpoints include:

  • /debug/pprof/profile – CPU profile (query with ?seconds=30)
  • /debug/pprof/heap – Memory heap snapshot
  • /debug/pprof/goroutine – Stack traces of all live goroutines
  • /debug/pprof/allocs – Historical memory allocations

Capturing a CPU Profile


# Start FastProxy (default port 8080)

./fast_proxy_server &

# Record a 30‑second CPU profile and open the interactive web UI

go tool pprof -http=:8081 http://localhost:8080/debug/pprof/profile?seconds=30

The command launches a browser interface on http://localhost:8081 where you can explore flame graphs, top functions, and source‑level hot spots.

Inspecting Heap Usage

curl -s http://localhost:8080/debug/pprof/heap | go tool pprof -http=:8082 -

This opens a heap analysis view on port 8082, helping you identify memory leaks or high‑allocation paths in the proxy implementation.

Downloading a Goroutine Dump

curl http://localhost:8080/debug/pprof/goroutine?debug=2 > goroutine.txt

The resulting text file lists every active goroutine with its stack trace, useful for diagnosing deadlocks or worker pool exhaustion.

Graceful Shutdown Metrics

When FastProxy receives a termination signal, it logs the duration required to drain active connections and prints final statistics. This shutdown telemetry is implemented in common/server/server.go and helps verify that no requests were dropped during deployment or restart cycles.

Key Source Files for Observability

File Purpose
outproxy/outproxy.go Entry point for the out‑proxy server; imports net/http/pprof and registers the requestProxy handler.
common/server/server.go Core server implementation; wires /debug/pprof into the HTTP/Fast‑HTTP router and handles graceful shutdown logging.
common/logger/zap/* Structured logging infrastructure used by all proxy implementations to emit JSON request logs.
outproxy/internal/proxy/* Concrete proxy logic that forwards traffic and invokes the logger for each request/response pair.

Summary

  • Request logging is automatic: every transaction through outproxy/outproxy.go emits structured JSON via the zap logger in common/logger/zap.
  • Runtime profiling is available at /debug/pprof thanks to the import in outproxy/outproxy.go and the server wiring in common/server/server.go.
  • No external agents are required; you can monitor traffic passing through FastProxy using standard Unix tools and the Go toolchain.

Frequently Asked Questions

How do I enable request logging in FastProxy?

Request logging is enabled by default. The zap logger in common/logger/zap is initialized automatically when the server starts, and the requestProxy handler in outproxy/outproxy.go writes a JSON line for every HTTP transaction to stdout.

Can I integrate FastProxy metrics with Prometheus?

FastProxy does not include a native Prometheus exporter, but you can bridge the structured logs to Prometheus using a tool like Promtail or by adding a middleware wrapper in outproxy/internal/proxy/* that increments counters and observes latencies for each request.

Where are the pprof endpoints mounted?

The pprof endpoints are mounted at /debug/pprof on the same port that FastProxy listens for proxy traffic. This is configured in common/server/server.go and activated by the blank import _ "net/http/pprof" in outproxy/outproxy.go.

What information is included in the graceful shutdown logs?

When FastProxy receives a termination signal, the shutdown routine in common/server/server.go logs the elapsed time required to close the listener and drain active connections, confirming that all in‑flight requests completed before the process exited.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →