Skip to content

Commit 0b64df7

Browse files
DOCS-2254: Add debug endpoints documentation for viam-server (#4317)
1 parent 9104f6d commit 0b64df7

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

docs/manage/troubleshoot/troubleshoot.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,27 @@ The process will dump a stack trace, visible in the `viam-server` logs, that sho
183183
Some issues are due to overall system health.
184184
To rule out machine health as the root cause of your issues, [add a machine telemetry sensor](/manage/troubleshoot/alert/#add-performance-sensor) and [capture machine telemetry data with the data management service](/manage/troubleshoot/alert/#configure-data-management).
185185

186+
## Use `viam-server` debug endpoints
187+
188+
You can use [`pprof`](https://pkg.go.dev/net/http/pprof) to:
189+
190+
- diagnose performance bottlenecks
191+
- investigate memory leaks
192+
- understand resource usage patterns
193+
- troubleshoot high CPU or memory usage
194+
195+
To enable the pprof endpoints, set `enable_web_profile` to `true` in your machine configuration:
196+
197+
```json
198+
{
199+
"components": [...],
200+
"services": [...],
201+
"enable_web_profile": true
202+
}
203+
```
204+
205+
For more information on advanced debugging endpoints, see [Advanced debug endpoints](/operate/reference/viam-server/debug-endpoints/).
206+
186207
## Remote shell on the machine
187208

188209
To remotely access your machine from your terminal:
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: "Debug Endpoints"
3+
linkTitle: "Debug Endpoints"
4+
weight: 130
5+
type: "docs"
6+
description: "Advanced debugging endpoints available in viam-server for troubleshooting and development."
7+
date: "2025-05-19"
8+
---
9+
10+
The RDK (Robot Development Kit) that powers `viam-server` includes several debug endpoints that expose server internals.
11+
These endpoints can be helpful during development or when troubleshooting complex issues:
12+
13+
- [`pprof`](#pprof)
14+
- [`graph`](#graph)
15+
16+
## `pprof`
17+
18+
Setting `enable_web_profile` to `true` in your machine configuration allows you to visualize runtime profiling data by opening a locally hosted webpage that displays profiling data.
19+
The pprof tool provides the following information about machine performance:
20+
21+
- CPU usage
22+
- Memory allocation
23+
- Goroutine blocking
24+
- Execution tracing
25+
26+
For more detailed information on using pprof, refer to the [Go pprof documentation](https://pkg.go.dev/net/http/pprof).
27+
28+
### Configuration
29+
30+
To enable the pprof endpoints, set `enable_web_profile` to `true` in your machine configuration:
31+
32+
1. Navigate to the **CONFIGURE** tab of your machine in the Viam app
33+
1. Click on the **...** menu next to your machine part in the left-hand menu
34+
1. Select **Edit JSON**
35+
1. Add the `enable_web_profile` field at the root level of your configuration:
36+
37+
```json
38+
{
39+
"components": [...],
40+
"services": [...],
41+
"enable_web_profile": true
42+
}
43+
```
44+
45+
{{< alert title="Caution" color="caution" >}}
46+
The debug endpoints expose internal details about your machine's configuration and runtime behavior.
47+
Only enable these endpoints in development environments.
48+
{{< /alert >}}
49+
50+
### Available Endpoints
51+
52+
Once enabled, you can access the pprof interface by navigating to `https://localhost:8080/debug/pprof/` in your browser.
53+
54+
The following pprof routes are available:
55+
56+
- `/debug/pprof/cmdline`: Command line arguments used to start the process
57+
- `/debug/pprof/profile`: CPU profile data (30-second sample by default)
58+
- `/debug/pprof/symbol`: Symbol lookup for program counters
59+
- `/debug/pprof/trace`: Execution trace data
60+
61+
## `graph`
62+
63+
The `/debug/graph` endpoint shows a graphical representation of the machine resources managed by the RDK.
64+
65+
To access this endpoint, visit `https://localhost:8080/debug/graph` on the machine.
66+
67+
### Layout Options
68+
69+
To view different [layouts](https://graphviz.org/docs/layouts/), use the `layout` query parameter:
70+
71+
The following example URL specifies the `circo` layout:
72+
73+
```txt
74+
https://localhost:8080/debug/graph?layout=circo
75+
```
76+
77+
Available layout options include:
78+
79+
- `dot` (default): Hierarchical layout
80+
- `neato`: Spring model layout
81+
- `fdp`: Force-directed layout
82+
- `sfdp`: Multiscale version of fdp for large graphs
83+
- `circo`: Circular layout
84+
- `twopi`: Radial layout
85+
- `osage`: Array-based layout
86+
- `text`: raw [DOT](https://graphviz.org/doc/info/lang.html) text of the graph, for use with external tools
87+
88+
## Next Steps
89+
90+
{{< cards >}}
91+
{{% card link="/manage/troubleshoot/troubleshoot/" %}}
92+
{{% card link="/operate/reference/viam-server/manage-viam-server/" %}}
93+
{{% card link="/dev/tools/common-errors/" %}}
94+
{{< /cards >}}

0 commit comments

Comments
 (0)