Skip to main content

Cloudflare Tunnel Monitor smart home integration, free and open source

Cloudflare Tunnel Monitor integration for Gladys Assistant

Monitor your Cloudflare tunnels: status, connections, alerts and scenes.

This integration watches your Cloudflare tunnels (cloudflared) from Gladys: is each tunnel up, how many connections does it hold, and is the cloudflared running in your home still connected? Every tunnel becomes a Gladys device, a status change can start a scene, and a dashboard widget shows everything at a glance.

It only reads: it never creates, changes or deletes a tunnel.

Two sources, use one or both​

SourceWhat you needWhat you get
CloudA Cloudflare API token and your account IDEvery tunnel of the account, with the status Cloudflare computes
LocalThe metrics address of a cloudflared on LANThat connector's own state — still answering when the Internet is down

Use both for the best result: the cloud sees every tunnel, the local connector keeps answering when the Internet link is what broke.

Cloud: create the API token​

  1. Open the Cloudflare dashboard, then My Profile → API Tokens (https://dash.cloudflare.com/profile/api-tokens).
  2. Create Token → Custom token → Get started.
  3. Give it a name (e.g. Gladys), and add one permission: Account → Cloudflare Tunnel → Read.
  4. Under Account Resources, include the account that holds your tunnels.
  5. Continue to summary → Create Token, then copy the token. Cloudflare shows it only once.

The token is read-only: even if it leaked, nobody could change a tunnel with it.

Cloud: find the account ID​

In the Cloudflare dashboard, open your account: the Account ID is shown on the Overview page (right column), or in the account menu → Copy account ID. It is 32 characters, digits and letters a to f.

Local: expose the metrics of cloudflared​

cloudflared has a small metrics server. By default it only listens on the machine itself, on a random port: give it a fixed address Gladys can reach.

  • Command line: add --metrics 0.0.0.0:2000, for example cloudflared tunnel --metrics 0.0.0.0:2000 run --token <tunnel token>.
  • config.yml: add the line metrics: 0.0.0.0:2000.
  • Docker: same option in the command, and publish the port (-p 2000:2000).

Check from another machine: curl http://<cloudflared host>:2000/ready must answer something like {"status":200,"readyConnections":4,"connectorId":"…"}.

The metrics server shows no secret, but keep it on your local network: do not open that port to the Internet.

Configuration​

FieldMeaning
Cloudflare API tokenThe token created above. Leave empty to use local connectors only.
Cloudflare account IDThe 32-character ID found above.
Local cloudflared connectorsMetrics addresses, separated by commas: http://192.168.1.10:2000, http://nas.lan:2000.
Check interval (s)Seconds between two checks, 30 to 3600 (default 60).

The Prefer the local connection switch, shown by Gladys under the form, decides which source is shown for a tunnel that has both (see below).

Then click Test the connection: the answer says, for each source, what answered and what to fix.

Devices​

The devices appear in the Discover tab of the integration: add the ones you want to follow.

One device per tunnel (cloud)​

FeatureValues
Statushealthy, degraded, down or inactive
Online1 when the tunnel carries traffic (healthy or degraded), 0 otherwise
Active connectionsNumber of connections to the Cloudflare edge

What the statuses mean, as Cloudflare defines them:

  • healthy: the tunnel works normally;
  • degraded: it still carries traffic, but some connections or connectors are missing;
  • down: no connection left, the tunnel cannot carry traffic;
  • inactive: the tunnel has never been run.

Renaming a tunnel in Cloudflare keeps its Gladys device: the device is tied to the tunnel ID, not to its name.

One device per local connector​

FeatureValues
Ready1 when the connector holds at least one connection
Ready connectionsNumber of connections it holds (4 by default)

The badge on each device​

  • local: the state comes from a cloudflared on your network;
  • cloud: it comes from the Cloudflare API;
  • unreachable: no source answers for this device.

When a local connector serves a tunnel of your account, the integration links them on its own (through the connector ID Cloudflare reports). Then, with Prefer the local connection on, the tunnel shows the local view; off, the Cloudflare view. If the preferred source fails, the other one stands in and the badge gets an orange dot with the reason.

Scenes​

Triggers​

  • A Cloudflare tunnel changes status — filter on the tunnel and on the new status. Variables: tunnel name, new status, previous status, active connections. Example: "when the home tunnel becomes Down, send me a message".
  • A local cloudflared connector changes status — filter on the connector and on Ready, Not ready, Unreachable.
  • The Cloudflare API stops answering — fired once when the API starts failing (token refused, unknown account, no Internet…), not at every check.

Each trigger fires once per change. The last known status is kept on disk, so a change that happens while Gladys restarts is still caught.

Actions​

  • Check the Cloudflare tunnels now — runs a check at once. Gives: number of tunnels, healthy tunnels, tunnels with an issue, and "all tunnels healthy" (yes/no), to test in the next actions.
  • Read the status of a tunnel — gives the name, status, online (yes/no) and active connections of a tunnel or a local connector, from the last check.

Dashboard widget​

Add the Cloudflare tunnels widget to a dashboard. It shows:

  • the number of healthy tunnels, and of tunnels with an issue;
  • the number of local connectors ready (when you have some);
  • one line per tunnel (issues first) and per connector, with its status and connections;
  • a Check now button.

Troubleshooting​

MessageWhat to do
Cloudflare refused the API tokenCheck the token, and its permission Account → Cloudflare Tunnel → Read.
Cloudflare does not know this account IDCopy the account ID again; check the token includes this account.
The Cloudflare API cannot be reachedCheck that Gladys has Internet access (DNS, firewall).
A connector shows no answerCheck --metrics 0.0.0.0:<port> on cloudflared, the port, and curl http://host:port/ready.
A connector answers but holds no connectioncloudflared runs but cannot reach Cloudflare: check its own logs.

Privacy​

The token is stored in Gladys and sent only to api.cloudflare.com, over HTTPS. It is never written to the logs. Local connectors are read on your network, without any token.

Configuration settings​

These are the settings Cloudflare Tunnel Monitor asks for in its configuration screen in Gladys.

SettingTypeRequiredDescription
Getting startedsectionNoTwo sources, use one or both. Cloud: a Cloudflare API token with the permission Account › Cloudflare Tunnel › Read, and your account ID — every tunnel of the account becomes a device. Local: the metrics address of a cloudflared connector on your network (started with --metrics 0.0.0.0:2000) — it keeps answering when the Internet link is down.
Cloudflare API tokensecretNoRead-only token: Account › Cloudflare Tunnel › Read. Leave empty to use local connectors only.
Cloudflare account IDstringNo32 hexadecimal characters, shown on the Overview page of the Cloudflare dashboard.
Local cloudflared connectorsstringNoMetrics addresses of your cloudflared instances, separated by commas. Leave empty to use the Cloudflare API only.
Check interval (s)numberNoSeconds between two checks of every tunnel and connector (30 to 3600).

How to install Cloudflare Tunnel Monitor in Gladys​

  1. In Gladys, open Integrations: Cloudflare Tunnel Monitor appears in the catalog, next to the native integrations, with a community badge.
  2. Click Install. Gladys pulls the Docker image (ghcr.io/prohand/gladys-cloudflaretunnelmonitor:0.0.1), starts it in a sandbox isolated from the core, and generates the integration's interface (devices, discovery and configuration).
  3. Open the Configuration screen of the integration, fill in the settings, and save.
  4. You can also install it directly from its repository URL: https://github.com/prohand/gladys-cloudflaretunnelmonitor.

Cloudflare Tunnel Monitor requires Gladys >=5.1.0. The catalog inside Gladys refreshes every hour, so a new version becomes available at most one hour after its release.

Not running Gladys yet? It is free and open source: follow the installation guide to get started.

About external integrations​

Cloudflare Tunnel Monitor is an external integration: a community integration packaged as a Docker container and published on GitHub, that Gladys installs in one click and runs in a sandbox isolated from its core. It is published and maintained by prohand, not by the Gladys core team.

Subscribe to the Gladys Assistant newsletter

A few emails per month about new releases and project news. Sent by Pierre-Gilles Leymarie, founder of the project. Unsubscribe anytime 🙂