|
| 1 | +--- |
| 2 | +pcx_content_type: how-to |
| 3 | +title: Tunnel diagnostic logs |
| 4 | +sidebar: |
| 5 | + order: 1 |
| 6 | + label: Diagnostic logs |
| 7 | +--- |
| 8 | + |
| 9 | +import {Details} from "~/components"; |
| 10 | + |
| 11 | +Cloudflare Tunnel generates a set of diagnostic logs that can be used to troubleshoot issues with `cloudflared`. A diagnostic report collects data from a single instance of `cloudflared` running on the local machine. |
| 12 | + |
| 13 | +## Get diagnostic logs |
| 14 | + |
| 15 | +The steps for getting diagnostic logs depend on your `cloudflared` deployment environment. |
| 16 | + |
| 17 | +### Prerequisites |
| 18 | + |
| 19 | +- `cloudflared` version 2024.12.2 or later installed on the host |
| 20 | + |
| 21 | +### Host environment |
| 22 | + |
| 23 | +These instructions apply to remotely-managed and locally-managed tunnels running directly on the host machine. |
| 24 | + |
| 25 | +1. (Linux only) To include network diagnostics in the logs, allow the `cloudflared` user to create RAW and PACKET sockets without root permissions: |
| 26 | + |
| 27 | + ```sh |
| 28 | + sudo setcap cap_net_raw+ep /usr/bin/traceroute && sudo setcap cap_net_raw+ep /usr/bin/traceroute |
| 29 | + ``` |
| 30 | + |
| 31 | + If you do not set `cap_net_raw`, then traceroute data will be unavailable. |
| 32 | + |
| 33 | +2. Get diagnostic logs: |
| 34 | + |
| 35 | + ```sh |
| 36 | + cloudflared tunnel diag |
| 37 | + ``` |
| 38 | + |
| 39 | + If multiple instances of `cloudflared` are running on the same host, specify the [metrics server IP and port](/cloudflare-one/connections/connect-networks/monitor-tunnels/metrics/#check-the-metrics-server-address) for the instance you want to diagnose. For example: |
| 40 | + |
| 41 | + ```sh |
| 42 | + cloudflared tunnel diag --metrics 127.0.0.1:20241 |
| 43 | + ``` |
| 44 | + |
| 45 | +This command will output the status of each diagnostic task and place a `cloudflared-diag-YYYY-MM-DDThh-mm-ss.zip` file in your working directory. |
| 46 | + |
| 47 | +### Docker |
| 48 | + |
| 49 | +`cloudflared` reads diagnostic data from the [tunnel metrics server](/cloudflare-one/connections/connect-networks/monitor-tunnels/metrics/). To get diagnostic logs, the metrics server must be exposed from the Docker container and reachable from the host machine. |
| 50 | + |
| 51 | +1. Determine the [metrics server port](/cloudflare-one/connections/connect-networks/monitor-tunnels/metrics/#default-metrics-server-address) for the `cloudflared` instance running in Docker. |
| 52 | + |
| 53 | +2. Ensure the container is deployed with port forwarding enabled. The diagnostic feature will request information from the Docker instance using local port `20241`, therefore you should forward port `20241` to the container port obtained in Step 1: |
| 54 | + |
| 55 | + ```sh |
| 56 | + docker run -d -p 20241:<metrics_port> docker.io/cloudflare/cloudflared tunnel ... |
| 57 | + ``` |
| 58 | + |
| 59 | +3. Verify that you can reach the metrics server address from the Docker host environment: |
| 60 | + |
| 61 | + ```curl |
| 62 | + curl localhost:20241/diag/tunnel |
| 63 | + ``` |
| 64 | + |
| 65 | + This command should return a JSON: |
| 66 | + ```json |
| 67 | + { |
| 68 | + "tunnelID": "ef96b330-a7f5-4bce-a00e-827ce5be077f", |
| 69 | + "connectorID": "d236670a-9f74-422f-adf1-030f5c5f0523", |
| 70 | + "connections": [ |
| 71 | + { "isConnected": true, "protocol": 1, "edgeAddress": "198.41.192.167"}, |
| 72 | + {"isConnected": true, "protocol": 1, "edgeAddress": "198.41.200.113", "index": 1}, |
| 73 | + {"isConnected": true, "protocol": 1, "edgeAddress": "198.41.192.47", "index": 2}, |
| 74 | + {"isConnected": true, "protocol": 1, "edgeAddress": "198.41.200.73", "index": 3} |
| 75 | + ], |
| 76 | + "icmp_sources": ["192.168.1.243", "fe80::c59:bd4a:e815:ed6"] |
| 77 | + } |
| 78 | + ``` |
| 79 | + |
| 80 | +4. Run the diagnostic using the Docker container ID: |
| 81 | + |
| 82 | + ```sh |
| 83 | + cloudflared tunnel diag --diag-container-id=<containerID> |
| 84 | + ``` |
| 85 | + |
| 86 | + Alternatively, you can specify the container's name instead of its ID: |
| 87 | + ```sh |
| 88 | + cloudflared tunnel diag --diag-container-id=<containerName> |
| 89 | + ``` |
| 90 | + |
| 91 | + Running the diagnostic command with the container ID allows `cloudflared` to collect information from the Docker environment such as logs and container details. |
| 92 | + |
| 93 | +This command will output the status of each diagnostic task and place a `cloudflared-diag-YYYY-MM-DDThh-mm-ss.zip` file in your working directory. |
| 94 | + |
| 95 | +### Kubernetes |
| 96 | + |
| 97 | +The diagnostic feature will request data from the [tunnel metrics server](/cloudflare-one/connections/connect-networks/monitor-tunnels/metrics/) using ports `20241` to `20245`. You will need to use port forwarding to allow the local `cloudflared` instance to connect to the metrics server on one of these ports. |
| 98 | + |
| 99 | +1. Determine the tunnel's [metrics server port](/cloudflare-one/connections/connect-networks/monitor-tunnels/metrics/#default-metrics-server-address). |
| 100 | + |
| 101 | +2. Enable port forwarding: |
| 102 | + |
| 103 | + ```sh |
| 104 | + kubectl port-forward <pod> <diagnostic_port>:<metrics_port> |
| 105 | + ``` |
| 106 | + |
| 107 | + - `<pod>`: Name of the pod where the tunnel is running |
| 108 | + - `<diagnostic_port>` is any local port in the range `20241` to `20245`. |
| 109 | + - `<metrics_port>` is the Kubernetes pod port for the `cloudflared` instance you want to diagnose (obtained in Step 1). |
| 110 | + |
| 111 | + For example, if you set the metrics server address to `0.0.0.0:12345`: |
| 112 | + |
| 113 | + ```sh |
| 114 | + kubectl port-forward cloudflared-6d4897585b-r8kfz 20244:12345 |
| 115 | + ``` |
| 116 | + Connections made to local port `20244` are forwarded to port `12345` of the pod that is running the tunnel. |
| 117 | + |
| 118 | +3. Run the diagnostic: |
| 119 | + |
| 120 | + ```sh |
| 121 | + cloudflared tunnel diag --diag-pod-id=<podID> |
| 122 | + ``` |
| 123 | + |
| 124 | + If the pod has multiple applications/services running and `cloudflared` is not the first in the pod, you must specify either the container ID or name: |
| 125 | + |
| 126 | + ```sh |
| 127 | + cloudflared tunnel diag --diag-pod-id=<podID> --diag-container-id=<containerName> |
| 128 | + ``` |
| 129 | + |
| 130 | +This command will output the status of each diagnostic task and place a `cloudflared-diag-YYYY-MM-DDThh-mm-ss.zip` file in your working directory. |
| 131 | + |
| 132 | +## cloudflared-diag files |
| 133 | + |
| 134 | +The `cloudflared-diag-YYYY-MM-DDThh-mm-ss.zip` archive contains the files listed below. The data in a file either applies to the `cloudflared` instance being diagnosed (`diagnosee`) or the instance that triggered the diagnosis (`diagnoser`). For example, if your tunnel is running in a Docker container, the diagnosee is the Docker instance and the diagnoser is the host instance. |
| 135 | + |
| 136 | +| File name | Description | Instance | |
| 137 | +| -| - | - | |
| 138 | +| `cli-configuration.json`| [Tunnel run parameters](/cloudflare-one/connections/connect-networks/configure-tunnels/tunnel-run-parameters/) used when starting the tunnel | diagnosee| |
| 139 | +| `cloudflared_logs.txt` | [Tunnel log file](/cloudflare-one/connections/connect-networks/monitor-tunnels/logs/)[^1] | diagnosee| |
| 140 | +| `configuration.json` | Tunnel configuration parameters | diagnosee| |
| 141 | +| `goroutine.pprof` | goroutine profile made available by `pprof` | diagnosee| |
| 142 | +| `heap.pprof` | heap profile made available by `pprof`| diagnosee| |
| 143 | +| `metrics.txt` | Snapshot of [Tunnel metrics](/cloudflare-one/connections/connect-networks/monitor-tunnels/metrics/#available-metrics) at the time of diagnosis | diagnosee| |
| 144 | +| `network.txt` | JSON traceroutes to Cloudflare's global network using IPv4 and IPv6 | diagnoser| |
| 145 | +| `raw-network.txt` | Raw traceroutes to Cloudflare's global network using IPv4 and IPv6 | diagnoser| |
| 146 | +| `systeminformation.json` | Operating system information and resource usage | diagnosee| |
| 147 | +| `task-result.json` | Result of each diagnostic task | diagnoser | |
| 148 | +| `tunnelstate.json` | Tunnel connections at the time of diagnosis| diagnosee| |
| 149 | + |
| 150 | +[^1]: If the log file is blank, you may need to [set `--loglevel` to `debug`](/cloudflare-one/connections/connect-networks/monitor-tunnels/logs/#view-logs-on-the-server) when you start the tunnel. The `--loglevel` parameter is only required if you ran the tunnel from the CLI using a `cloudflared tunnel run` command. It is not necessary if the tunnel runs as a Linux/macOS service or runs in Docker/Kubernetes. |
0 commit comments