Documentation
v1
Advanced
Stats API

Stats API

MekongTunnel exposes a live admin dashboard and JSON endpoints on 127.0.0.1:9090. Requests from loopback (127.0.0.1 / ::1) are always allowed. Requests from any other address are rejected with 403 Forbidden unless they send an X-Tunnel-Secret header that matches the server's TUNNEL_EDGE_SECRET (this is how the API talks to a tunnel server on another machine).

Web Dashboard

http://127.0.0.1:9090/

A live HTML dashboard for server operators. It shows:

  • Active tunnel count
  • Total requests served
  • Total SSH connections
  • Blocked IPs count
  • Live table of all active tunnels: subdomain, client IP, uptime, request count

The dashboard auto-refreshes every 3 seconds — no page reload needed.


JSON API

GET http://127.0.0.1:9090/api/stats

Returns current server metrics as JSON. Useful for monitoring tools, shell scripts, or custom dashboards. Add ?subdomains=true to also get a plain subdomains list.

Response

{
  "active_tunnels": 2,
  "unique_ips": 2,
  "total_connections": 15,
  "total_requests": 1247,
  "tunnels": [
    {
      "subdomain": "myapp",
      "user_id": "6f1c…",
      "client_ip": "1.2.3.4",
      "uptime_secs": 842,
      "request_count": 120,
      "today_requests": 80,
      "total_bytes": 524288,
      "today_bytes": 262144,
      "local_port": 3000,
      "last_active_at": "2026-01-01T12:00:00Z",
      "started_at": "2026-01-01T11:46:00Z"
    },
    {
      "subdomain": "happy-tiger-a1b2c3d4",
      "client_ip": "5.6.7.8",
      "uptime_secs": 310,
      "request_count": 45,
      "today_requests": 45,
      "total_bytes": 81920,
      "today_bytes": 81920,
      "local_port": 8080,
      "last_active_at": "2026-01-01T12:00:00Z",
      "started_at": "2026-01-01T11:54:50Z"
    }
  ],
  "blocked_ips": 1,
  "total_blocked": 3,
  "total_rate_limited": 0
}

Fields

FieldTypeDescription
active_tunnelsintegerNumber of currently open tunnels
unique_ipsintegerNumber of unique client IPs with active tunnels
total_connectionsintegerTotal SSH connections accepted since server start
total_requestsintegerTotal HTTP requests proxied since server start
subdomainsarrayActive subdomain names — only with ?subdomains=true
tunnelsarrayPer-tunnel details (see below)
blocked_ipsintegerNumber of currently active (non-expired) IP blocks
total_blockedintegerIPs blocked since server start
total_rate_limitedintegerRate-limit rejections since server start

Each entry in tunnels has subdomain, user_id (only for tunnels linked to an account), client_ip, uptime_secs, request_count, today_requests, total_bytes, today_bytes, local_port, last_active_at and started_at.

Other endpoints

EndpointReturns
GET /api/tunnels/liveJSON array of tunnel entries (same shape as tunnels above). Filter with ?user_id= and/or ?subdomain=
GET /api/tunnels/logs/<subdomain>{ "subdomain", "active", "lines" } — recent request log lines for an active tunnel (404 if it is not active)
GET /api/tunnels/logs/<subdomain>?stream=sseThe same log as a Server-Sent Events stream (follow=true also works)

Examples

# Get JSON stats
curl http://127.0.0.1:9090/api/stats
 
# Pretty-print
curl -s http://127.0.0.1:9090/api/stats | jq .
 
# Watch active tunnel count every 30 seconds
watch -n 30 'curl -s http://127.0.0.1:9090/api/stats | jq .active_tunnels'
 
# From another host (needs the shared secret)
curl -H "X-Tunnel-Secret: $TUNNEL_EDGE_SECRET" http://10.0.0.5:9090/api/stats

Port configuration

The stats port can be changed with the STATS_ADDR environment variable:

STATS_ADDR=127.0.0.1:9091
⚠️

If you bind STATS_ADDR to a non-loopback address, only requests carrying the matching X-Tunnel-Secret header are answered. Without TUNNEL_EDGE_SECRET set, everything except loopback gets 403. Keep the port firewalled anyway.