← All posts
Open Source 8 min read

tunmon: When Your Tunnel Is Down, Know Exactly Why

A Cloudflare 502 is not “the internet is broken.” tunmon doctor walks the path a request takes and tells you the origin refused port 5000 — then keeps watching in the background.

View on GitHub
Terminal demo of tunmon doctor reporting HEALTHY and DOWN hostnames with origin refused on port 5000

tunmon is a Linux tool I built because “tunnel is down” is not a diagnosis. cloudflared and ngrok sit between the public internet and a local origin; a red status could be the connector, DNS, the certificate, the edge, or the app on localhost. tunmon walks that path in order and names the first break.

Source: github.com/mr-Imran/tunmon (MIT). Static musl releases for Linux x86_64 and ARM64. Zero-config discovery; optional TOML for alerts and custom targets.

Example tunmon doctor output with one healthy and one down hostname
doctor output — connector, DNS, and TLS pass; edge 502 maps to origin connection refused on :5000.

Install

									curl -fsSL https://github.com/mr-Imran/tunmon/releases/latest/download/install.sh | sh

tunmon doctor          # one-shot diagnosis
tunmon watch           # continuous terminal checks
tunmon gui             # desktop dashboard window
tunmon uninstall       # remove; add --purge for settings + history
								

The installer verifies checksums, puts tunmon in ~/.local/bin, registers a systemd user service when systemd is present, and opens the UI. Re-run to upgrade in place. Without systemd (some containers/WSL), use tunmon gui or tunmon daemon directly.

Real use cases

1. Homelab: self-hosted apps behind Cloudflare Tunnel

You expose Immich, Home Assistant, a reverse proxy, and a few side projects through one cloudflared connector. At 2 a.m. api.home.example.com returns 502. Without tunmon you SSH in and guess: DNS? cert? docker compose down? doctor shows connector healthy, DNS on Cloudflare IPs, TLS valid, edge 502, origin refused on the mapped port — fix: start the container or correct the service URL in the tunnel ingress. Hostnames stay remembered when the client stops, so they show as down with “restart this service” instead of vanishing from the list.

2. Client demos and staging on ngrok / cloudflared

Before a walkthrough you run tunmon doctor on the shared hostname. Green means the laptop origin is up; red with a hint means you fix locally before the call. During the week, tunmon daemon + Slack/Discord webhooks page you when staging flips down or recovers (after fail_threshold consecutive bad rounds so one blip does not spam). Alert shell hooks get TUNMON_HOST, TUNMON_STATE, TUNMON_CAUSE, and TUNMON_HINT for custom scripts.

3. Turning Cloudflare 502 into a root cause

Public HTTP 502 from a tunnel is ambiguous. tunmon distinguishes: nothing listening on the origin port; the app answering 500 locally; or a likely http vs https mismatch when localhost works but the edge path fails. That is the difference between “restart nginx” and “edit the ingress service line.”

Check orderQuestion answered
connectorIs cloudflared/ngrok running and connected to the edge?
dnsDoes the name resolve (local + public) to the tunnel provider?
tcp / tlsCan we reach :443, and is the cert valid / not expiring?
edgeWhat does a real request through the tunnel return, how fast?
originDoes the local service answer when asked directly?

4. Bandwidth and Prometheus for tunnel traffic

The daemon samples cloudflared connectors (every 2 s while the dashboard is open, else 30 s) and exposes /metrics plus JSON under 127.0.0.1:7878. You get bytes in/out, requests per second, 24-hour counters, and totals since connector start. Caveat: figures are per connector, not per hostname; QUIC (cloudflared default) is needed for byte counts; ngrok traffic collection is not there yet.

5. Certificate and DNS regressions before users notice

TLS checks report days left on the edge certificate. DNS checks compare local resolution to public DNS (1.1.1.1 by default; disable with public_dns = ""). When someone points a hostname away from Cloudflare or a cert nears expiry, events and the dashboard show it before a client call does.

Daemon, GUI, and commands

  • tunmon daemon — history, alerts, dashboard, metrics on 127.0.0.1:7878
  • tunmon gui — Chrome/Chromium/Brave/Edge/Vivaldi app window (else default browser)
  • tunmon list / status / events / forget HOST / service install
  • tunmon config init — write ~/.config/tunmon/config.toml defaults
  • Optional [[target]] rows for /health paths, expect_status, or ignore

Who this is for

If you run Linux with cloudflared or ngrok in front of local services — homelab, indie staging, agency demos — tunmon is the doctor and the night watch. macOS/Windows ports and more tunnel backends (Tailscale Funnel, frp, SSH) are welcome contributions.

I maintain the project at github.com/mr-Imran/tunmon.

Frequently asked questions

What is tunmon?

tunmon is a free MIT-licensed Linux tool (x86_64 and ARM64) by Mohammad Nizam Uddin Imran that finds your cloudflared and ngrok hostnames and diagnoses why each one is healthy or down by checking connector, DNS, TCP/TLS, edge, and origin in order.

How do I install it?

curl -fsSL https://github.com/mr-Imran/tunmon/releases/latest/download/install.sh | sh — no sudo. It installs to ~/.local/bin, starts a systemd user service when available, and opens the dashboard.

Does it need a config file?

No for discovery: it finds cloudflared via /proc and the local status endpoint, and ngrok via 127.0.0.1:4040. Optional ~/.config/tunmon/config.toml adds webhooks, custom health paths, and ignore lists.

What does doctor do differently from a simple uptime ping?

It isolates the first broken stage. A public 502 with a healthy connector, DNS, and TLS becomes “nothing is listening on port 5000” or “app returns HTTP 500,” with a concrete fix line — not just DOWN.

How heavy is the daemon?

On a machine with 3 connectors and 11 hostnames at a 30-second interval: about 0.2% of one CPU core, 13 MB RAM, one thread. Dashboard polling pauses while the window is hidden.

Sources & citations