Add client cli debug (#186)

Add cli debug command and update outputs
This commit is contained in:
Viktor Liu
2024-05-15 18:09:29 +02:00
committed by GitHub
parent 6d43cb9dc2
commit 493803e20c
5 changed files with 263 additions and 28 deletions

View File

@@ -24,6 +24,7 @@ netbird [command] [subcommand] [flags]
Below is the list of global flags:
```shell
--admin-url string Admin Panel URL [http|https]://[host]:[port] (default "https://app.netbird.io")
-A, --anonymize anonymize IP addresses and non-netbird.io domains in logs and status output
-c, --config string Netbird config file location (default "/etc/netbird/config.json")
--daemon-addr string Daemon service address to serve CLI requests [unix|tcp]://[path|host:port] (default "unix:///var/run/netbird.sock")
--log-file string sets NetBird log path. If console is specified the the log will be output to stdout (default "/var/log/netbird/client.log")
@@ -122,6 +123,7 @@ Retrieves the peer status from the daemon service.
--filter-by-ips strings filters the detailed output by a list of one or more IPs, e.g., --filter-by-ips 100.64.0.100,100.64.0.200
--filter-by-names strings filters the detailed output by a list of one or more peer FQDN or hostnames, e.g., --filter-by-names peer-a,peer-b.netbird.cloud
--filter-by-status string filters the detailed output by connection status(connected|disconnected), e.g., --filter-by-status connected
-A, --anonymize anonymize IP addresses and non-netbird.io domains in the status output
-h, --help help for status
--ipv4 display only NetBird IPv4 of this peer, e.g., --ipv4 will output 100.64.0.33
--json display detailed status information in json format
@@ -134,12 +136,17 @@ netbird status
```
This will output:
```shell
Daemon status: Connected
OS: linux/amd64
Daemon version: 0.27.4
CLI version: 0.27.4
Management: Connected
Signal: Connected
Relays: 2/2 Available
Nameservers: 1/1 Available
NetBird IP: 100.119.62.6/16
Interface type: Kernel
Quantum resistance: false
Routes: -
Peers count: 2/3 Connected
```
@@ -159,9 +166,12 @@ Peers detail:
Direct: false
ICE candidate (Local/Remote): -/-
ICE candidate endpoints (Local/Remote): -/-
Last connection update: 2022-07-07 12:21:31
Last connection update: 26 seconds ago
Last Wireguard handshake: -
Transfer status (received/sent) 0 B/0 B
Quantum resistance: false
Routes: -
Latency: 10.74ms
Peer:
NetBird IP: 100.119.201.225
@@ -172,9 +182,12 @@ Peers detail:
Direct: true
ICE candidate (Local/Remote): host/host
ICE candidate endpoints (Local/Remote): -/-
Last connection update: 2022-07-07 12:21:32
Last Wireguard handshake: 2022-07-07 12:21:33
Last connection update: 26 seconds ago
Last Wireguard handshake: 25 seconds ago
Transfer status (received/sent) 2.0 KiB/355 B
Quantum resistance: false
Routes: 10.0.0.0/24
Latency: 20.14ms
Peer:
NetBird IP: 100.119.230.104
@@ -185,18 +198,27 @@ Peers detail:
Direct: true
ICE candidate (Local/Remote): host/host
ICE candidate endpoints (Local/Remote): -/-
Last connection update: 2022-07-07 12:21:33
Last Wireguard handshake: 2022-07-07 12:21:34
Last connection update: 26 seconds ago
Last Wireguard handshake: 24 seconds ago
Transfer status (received/sent) 2.4 MiB/532 KiB
Quantum resistance: false
Routes: -
Latency: 16.24ms
Daemon status: Connected
OS: linux/amd64
Daemon version: 0.27.4
CLI version: 0.27.4
Management: Connected to https://api.netbird.io:33073
Signal: Connected to https://signal2.wiretrustee.com:10000
Relays:
[stun:stun.netbird.io:5555] is Available
[turns:turn.netbird.io:443?transport=tcp] is Available
Nameservers:
[8.8.8.8:53, 8.8.4.4:53] for [.] is Available
NetBird IP: 100.119.62.6/16
Interface type: Kernel
Quantum resistance: false
Routes: -
Peers count: 2/3 Connected
```
To filter the peers' output by connection status, you can use the `--filter-by-status` flag with either "connected" or "disconnected" as value:
@@ -215,9 +237,12 @@ Peers detail:
Direct: true
ICE candidate (Local/Remote): host/host
ICE candidate endpoints (Local/Remote): -/-
Last connection update: 2022-07-07 12:21:32
Last Wireguard handshake: 2022-07-07 12:21:33
Last connection update: 28 seconds ago
Last Wireguard handshake: 27 seconds ago
Transfer status (received/sent) 2.0 KiB/355 B
Quantum resistance: false
Routes: 10.0.0.0/24
Latency: 20.14ms
Peer:
NetBird IP: 100.119.230.104
@@ -228,18 +253,27 @@ Peers detail:
Direct: true
ICE candidate (Local/Remote): host/host
ICE candidate endpoints (Local/Remote): -/-
Last connection update: 2022-07-07 12:21:33
Last Wireguard handshake: 2022-07-07 12:21:34
Last connection update: 28 seconds ago
Last Wireguard handshake: 26 seconds ago
Transfer status (received/sent) 2.4 MiB/532 KiB
Quantum resistance: false
Routes: -
Latency: 16.24ms
Daemon status: Connected
OS: linux/amd64
Daemon version: 0.27.4
CLI version: 0.27.4
Management: Connected to https://api.netbird.io:33073
Signal: Connected to https://signal2.wiretrustee.com:10000
Relays:
[stun:stun.netbird.io:5555] is Available
[turns:turn.netbird.io:443?transport=tcp] is Available
Nameservers:
[8.8.8.8:53, 8.8.4.4:53] for [.] is Available
NetBird IP: 100.119.62.6/16
Interface type: Kernel
Quantum resistance: false
Routes: -
Peers count: 2/3 Connected
```
To filter the peers' output by peer IP addresses, you can use the `--filter-by-ips` flag with one or more IPs separated by a comma as a value:
@@ -258,18 +292,27 @@ Peers detail:
Direct: true
ICE candidate (Local/Remote): host/host
ICE candidate endpoints (Local/Remote): -/-
Last connection update: 2022-07-07 12:21:32
Last Wireguard handshake: 2022-07-07 12:21:33
Last connection update: 32 seconds ago
Last Wireguard handshake: 30 seconds ago
Transfer status (received/sent) 2.0 KiB/355 B
Quantum resistance: false
Routes: 10.0.0.0/24
Latency: 20.14ms
Daemon status: Connected
OS: linux/amd64
Daemon version: 0.27.4
CLI version: 0.27.4
Management: Connected to https://api.netbird.io:33073
Signal: Connected to https://signal2.wiretrustee.com:10000
Relays:
[stun:stun.netbird.io:5555] is Available
[turns:turn.netbird.io:443?transport=tcp] is Available
Nameservers:
[8.8.8.8:53, 8.8.4.4:53] for [.] is Available
NetBird IP: 100.119.62.6/16
Interface type: Kernel
Quantum resistance: false
Routes: -
Peers count: 2/3 Connected
```
You can combine both filters and get the peers that are both connected and with specific IPs:
@@ -289,18 +332,27 @@ Peers detail:
Direct: true
ICE candidate (Local/Remote): host/host
ICE candidate endpoints (Local/Remote): -/-
Last connection update: 2022-07-07 12:21:33
Last Wireguard handshake: 2022-07-07 12:21:34
Last connection update: 35 seconds ago
Last Wireguard handshake: 33 seconds ago
Transfer status (received/sent) 2.4 MiB/532 KiB
Quantum resistance: false
Routes: -
Latency: 16.24ms
Daemon status: Connected
OS: linux/amd64
Daemon version: 0.27.4
CLI version: 0.27.4
Management: Connected to https://api.netbird.io:33073
Signal: Connected to https://signal2.wiretrustee.com:10000
Relays:
[stun:stun.netbird.io:5555] is Available
[turns:turn.netbird.io:443?transport=tcp] is Available
Nameservers:
[8.8.8.8:53, 8.8.4.4:53] for [.] is Available
NetBird IP: 100.119.62.6/16
Interface type: Kernel
Quantum resistance: false
Routes: -
Peers count: 2/3 Connected
```
<Note>
@@ -385,3 +437,115 @@ The minimal form of running the command is:
```shell
sudo netbird service stop
```
### debug
The `debug` command provides tools for diagnosing and understanding the internal operations of the NetBird daemon.
#### Usage
To access debugging options:
```shell
netbird debug [command]
```
#### Subcommands
- `bundle`: Create a debug bundle that includes logs and system information for troubleshooting.
- `for`: Run the daemon with trace logging for a specified duration and create a debug bundle.
- `log`: Manage logging levels for the NetBird daemon.
#### Flags
```shell
-h, --help help for debug
```
### debug bundle
Generates a compressed archive containing diagnostic information, which can be used for troubleshooting.
The file will be generated in the a temporary directory and the path will be printed to the console.
The file is only accessible as root/Administrator.
#### Usage
To create a debug bundle:
```shell
netbird debug bundle -A
```
#### Examples
Create a debug bundle:
```shell
netbird debug bundle
```
This will output:
```
/tmp/netbird.debug.676945815.zip
```
#### Flags
```shell
-h, --help help for bundle
-A, --anonymize anonymize IP addresses and non-netbird.io domains in the debug output
```
### debug for
Sets the logging level to trace, runs for the specified duration, and then generates a debug bundle.
This is useful for capturing detailed logs over a period where issues are occurring.
#### Usage
To run debugging for a specific time period:
```shell
netbird debug for <time> -A
```
#### Examples
Run debugging for 5 minutes and generate a debug bundle:
```shell
netbird debug for 5m
```
This will output:
```
Netbird down
Log level set to trace.
Netbird up
Remaining time: 00:00:01
Duration completed
Netbird down
Creating debug bundle...
/tmp/netbird.debug.2180993458.zip
```
#### Flags
```shell
-h, --help help for for
-A, --anonymize anonymize IP addresses and non-netbird.io domains in the debug output
```
### debug log
This subcommand manages the logging level for the NetBird daemon during the current session.
The change in logging level is temporary and will revert back to the configured default upon daemon restart.
#### Usage
Adjust the logging level of the NetBird daemon:
```shell
netbird debug log level <level>
```
#### Available Levels
- `panic`: for panic level, the highest level of severity.
- `fatal`: for fatal level errors that cause the program to exit.
- `error`: for error conditions.
- `warn`: for warning conditions.
- `info`: for informational messages.
- `debug`: for debug-level messages.
- `trace`: for trace-level messages, which include more fine-grained information than debug.
#### Examples
Set the logging level to debug:
```shell
netbird debug log level debug
```
This will output:
```
Log level set successfully to debug
```