Commit 504b7f3
[USM] Enhance USM debugging: add netstat command (#44610)
### What does this PR do?
1. Enhanced usm sysinfo command - Now displays detected service names alongside process information
2. New usm netstat command - Shows network connections similar to netstat -antpu with process information
usm sysinfo Enhancements
- Added "Service" column showing detected service names
- Detects DD_SERVICE environment variable from Docker containers and Kubernetes pods
- Falls back to generated service names using the same logic as process-agent
- Added --max-service-length flag (default: 20) to control service name display width
- Refactored to use service discovery infrastructure (envs.Variables, kernel.HostProc())
- Removed all magic numbers and strings, replaced with well-named constants
New usm netstat Command
- Displays active network connections (TCP/UDP, IPv4/IPv6)
- Maps connections to processes showing PID and process name
- Supports filtering: --tcp/-t, --udp/-u, --listening/-l flags
- Shows connection state (ESTABLISHED, LISTEN, TIME_WAIT, etc.)
- Optimized inode-to-PID mapping for performance
- Uses kernel.HostProc() for proper container/namespace support
### Motivation
When debugging USM issues, these commands provide essential diagnostic information:
For usm sysinfo:
- Verify service discovery is working correctly for target applications
- Confirm expected services are running and properly identified
- Validate service names match what's expected in USM monitoring
- Debug DD_SERVICE environment variable propagation in containers
For usm netstat:
- Identify which processes own specific network connections
- Debug USM connectivity issues
- Verify which processes are listening on ports
- Check established connections for monitored services
- Troubleshoot port conflicts
### Describe how you validated your changes
Manual Testing:
- Verified DD_SERVICE detection from Docker containers (-e DD_SERVICE=mysrv)
- Tested netstat with various flags (--tcp, --udp, --listening)
- Confirmed TCP state display (TIME_WAIT, ESTABLISHED, etc.)
- Validated process name and PID mapping for network connections
Testing:
- Added unit test for --max-service-length flag (default: 20)
### Additional Notes
Co-authored-by: guyarb <guy20495@gmail.com>
Co-authored-by: guy.arbitman <guy.arbitman@datadoghq.com>1 parent 876e309 commit 504b7f3
File tree
9 files changed
+425
-19
lines changed- cmd/system-probe/subcommands/usm
- pkg
- collector/corechecks/servicediscovery/module
- process/metadata/parser
9 files changed
+425
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
55 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
| |||
65 | 72 | | |
66 | 73 | | |
67 | 74 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
72 | 80 | | |
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
76 | 123 | | |
77 | 124 | | |
78 | 125 | | |
| |||
140 | 187 | | |
141 | 188 | | |
142 | 189 | | |
| 190 | + | |
| 191 | + | |
143 | 192 | | |
144 | 193 | | |
145 | 194 | | |
| |||
164 | 213 | | |
165 | 214 | | |
166 | 215 | | |
| 216 | + | |
167 | 217 | | |
168 | | - | |
169 | | - | |
170 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
171 | 232 | | |
172 | 233 | | |
173 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
| |||
0 commit comments