Skip to content

Commit 289abb3

Browse files
authored
docs: add TCP and UDP connection count fields to API documentation and examples for monitoring
1 parent e01c461 commit 289abb3

File tree

8 files changed

+98
-14
lines changed

8 files changed

+98
-14
lines changed

docs/en/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ API Key authentication is enabled by default. The key is auto-generated and stor
7373
"restart": true,
7474
"pool": 0,
7575
"ping": 0,
76+
"tcps": 0,
77+
"udps": 0,
7678
"tcprx": 0,
7779
"tcptx": 0,
7880
"udprx": 0,
@@ -81,6 +83,7 @@ API Key authentication is enabled by default. The key is auto-generated and stor
8183
```
8284

8385
- `pool`/`ping`: health check data, only available in debug mode
86+
- `tcps`/`udps`: current active connection count (TCP and UDP)
8487
- `tcprx`/`tcptx`/`udprx`/`udptx`: cumulative traffic stats
8588
- `restart`: auto-start policy
8689

docs/en/configuration.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ NodePass allows flexible configuration via URL query parameters. The following t
184184
| `mode` | Run mode control | O | O | X |
185185
| `read` | Data read timeout | O | O | X |
186186
| `rate` | Bandwidth rate limit | O | O | X |
187+
| `slot` | Maximum connection limit | O | O | X |
187188

188189
- O: Parameter is valid and recommended for configuration
189190
- X: Parameter is not applicable and should be ignored
@@ -201,7 +202,7 @@ NodePass behavior can be fine-tuned using environment variables. Below is the co
201202

202203
| Variable | Description | Default | Example |
203204
|----------|-------------|---------|---------|
204-
| `NP_SEMAPHORE_LIMIT` | Maximum number of concurrent connections | 1024 | `export NP_SEMAPHORE_LIMIT=2048` |
205+
| `NP_SEMAPHORE_LIMIT` | Signal channel buffer size | 1024 | `export NP_SEMAPHORE_LIMIT=2048` |
205206
| `NP_UDP_DATA_BUF_SIZE` | Buffer size for UDP packets | 8192 | `export NP_UDP_DATA_BUF_SIZE=16384` |
206207
| `NP_HANDSHAKE_TIMEOUT` | Timeout for handshake operations | 10s | `export NP_HANDSHAKE_TIMEOUT=30s` |
207208
| `NP_TCP_DIAL_TIMEOUT` | Timeout for establishing TCP connections | 30s | `export NP_TCP_DIAL_TIMEOUT=60s` |
@@ -242,10 +243,10 @@ The connection pool parameters are important settings for performance tuning in
242243

243244
#### Connection Management
244245

245-
- `NP_SEMAPHORE_LIMIT`: Controls the maximum number of concurrent tunnel operations
246-
- Too low: Rejected connections during traffic spikes
247-
- Too high: Potential memory pressure from too many concurrent goroutines
248-
- Recommended range: 1000-5000 for most applications, higher for high-throughput scenarios
246+
- `NP_SEMAPHORE_LIMIT`: Controls signal channel buffer size
247+
- Too small: May cause signal loss
248+
- Too large: Increased memory usage
249+
- Recommended range: 1000-5000
249250

250251
### UDP Settings
251252

@@ -266,10 +267,9 @@ For applications relying heavily on UDP traffic:
266267
For optimizing TCP connections:
267268

268269
- `NP_TCP_DIAL_TIMEOUT`: Timeout for establishing TCP connections
269-
- Default (10s) is suitable for most network conditions
270+
- Default (30s) is suitable for most network conditions
270271
- Increase for unstable network conditions
271272
- Decrease for applications that need quick connection success/failure determination
272-
- Affects initial connection establishment phase
273273

274274
### Pool Management Settings
275275

docs/en/examples.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,44 @@ This allows:
328328
- Custom URL paths for security or organizational purposes
329329
- Swagger UI access at http://localhost:9090/admin/v1/docs
330330

331+
### Example 17: Real-time Connection and Traffic Monitoring
332+
333+
Monitor instance connection counts and traffic statistics through the master API:
334+
335+
```bash
336+
# Get detailed instance information including connection count statistics
337+
curl -H "X-API-Key: your-api-key" http://localhost:9090/api/v1/instances/{id}
338+
339+
# Example response (including TCPS and UDPS fields)
340+
{
341+
"id": "a1b2c3d4",
342+
"alias": "web-proxy",
343+
"type": "server",
344+
"status": "running",
345+
"url": "server://0.0.0.0:10101/127.0.0.1:8080",
346+
"restart": true,
347+
"pool": 64,
348+
"ping": 25,
349+
"tcps": 12,
350+
"udps": 5,
351+
"tcprx": 1048576,
352+
"tcptx": 2097152,
353+
"udprx": 512000,
354+
"udptx": 256000
355+
}
356+
357+
# Use SSE to monitor real-time status changes for all instances
358+
curl -H "X-API-Key: your-api-key" \
359+
-H "Accept: text/event-stream" \
360+
http://localhost:9090/api/v1/events
361+
```
362+
363+
This monitoring setup provides:
364+
- **Real-time connection tracking**: TCPS and UDPS fields show current active connection counts
365+
- **Performance analysis**: Evaluate system load through connection and traffic data
366+
- **Capacity planning**: Resource planning based on historical connection data
367+
- **Troubleshooting**: Abnormal connection count changes may indicate network issues
368+
331369
## Next Steps
332370

333371
Now that you've seen various usage examples, you might want to:

docs/en/how-it-works.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ NodePass's data exchange mechanisms embody modern network programming best pract
360360
- Real-time byte-level traffic statistics, supporting precise bandwidth control
361361
- Protocol-specific traffic analysis, facilitating performance tuning
362362
- Connection-level performance metrics, supporting fine-grained monitoring
363+
- Real-time tracking of active TCP and UDP connection counts for capacity planning and performance analysis
363364

364365
### Protocol Optimization
365366
1. **TCP Optimization**:

docs/zh/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ API Key 认证默认启用,首次启动自动生成并保存在 `nodepass.gob`
7272
"restart": true,
7373
"pool": 0,
7474
"ping": 0,
75+
"tcps": 0,
76+
"udps": 0,
7577
"tcprx": 0,
7678
"tcptx": 0,
7779
"udprx": 0,
@@ -80,6 +82,7 @@ API Key 认证默认启用,首次启动自动生成并保存在 `nodepass.gob`
8082
```
8183

8284
- `pool`/`ping`:健康检查数据,仅 debug 模式下统计
85+
- `tcps`/`udps`:当前活动连接数统计(TCP和UDP)
8386
- `tcprx`/`tcptx`/`udprx`/`udptx`:累计流量统计
8487
- `restart`:自启动策略
8588

docs/zh/configuration.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ NodePass支持通过URL查询参数进行灵活配置,不同参数在 server
184184
| `mode` | 运行模式控制 | O | O | X |
185185
| `read` | 读取超时时间 | O | O | X |
186186
| `rate` | 带宽速率限制 | O | O | X |
187+
| `slot` | 最大连接数限制 | O | O | X |
187188

188189

189190
- O:参数有效,推荐根据实际场景配置
@@ -202,7 +203,7 @@ NodePass支持通过URL查询参数进行灵活配置,不同参数在 server
202203

203204
| 变量 | 描述 | 默认值 | 示例 |
204205
|----------|-------------|---------|---------|
205-
| `NP_SEMAPHORE_LIMIT` | 最大并发连接数 | 1024 | `export NP_SEMAPHORE_LIMIT=2048` |
206+
| `NP_SEMAPHORE_LIMIT` | 信号缓冲区大小 | 1024 | `export NP_SEMAPHORE_LIMIT=2048` |
206207
| `NP_UDP_DATA_BUF_SIZE` | UDP数据包缓冲区大小 | 8192 | `export NP_UDP_DATA_BUF_SIZE=16384` |
207208
| `NP_HANDSHAKE_TIMEOUT` | 握手操作超时 | 10s | `export NP_HANDSHAKE_TIMEOUT=30s` |
208209
| `NP_TCP_DIAL_TIMEOUT` | TCP连接建立超时 | 30s | `export NP_TCP_DIAL_TIMEOUT=60s` |
@@ -243,10 +244,10 @@ NodePass支持通过URL查询参数进行灵活配置,不同参数在 server
243244

244245
#### 连接管理
245246

246-
- `NP_SEMAPHORE_LIMIT`控制最大并发隧道操作数
247-
- 太低:流量高峰期拒绝连接
248-
- 太高:太多并发goroutine可能导致内存压力
249-
- 推荐范围:大多数应用1000-5000,高吞吐量场景更高
247+
- `NP_SEMAPHORE_LIMIT`控制信号缓冲区大小
248+
- 太小:容易导致信号丢失
249+
- 太大:内存使用增加
250+
- 推荐范围:1000-5000
250251

251252
### UDP设置
252253

@@ -267,10 +268,9 @@ NodePass支持通过URL查询参数进行灵活配置,不同参数在 server
267268
对于TCP连接的优化:
268269

269270
- `NP_TCP_DIAL_TIMEOUT`:TCP连接建立超时
270-
- 默认值(10s)适用于大多数网络条件
271+
- 默认值(30s)适用于大多数网络条件
271272
- 对于网络条件不稳定的环境增加此值
272273
- 对于需要快速判断连接成功与否的应用减少此值
273-
- 影响初始连接建立阶段
274274

275275
### 连接池管理设置
276276

docs/zh/examples.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,44 @@ curl -X POST http://localhost:9090/admin/v1/instances \
328328
- 用于安全或组织目的的自定义URL路径
329329
-http://localhost:9090/admin/v1/docs访问Swagger UI
330330

331+
### 示例17:实时监控连接数和流量
332+
333+
通过主控API监控实例的连接数和流量统计:
334+
335+
```bash
336+
# 获取实例详细信息,包括连接数统计
337+
curl -H "X-API-Key: your-api-key" http://localhost:9090/api/v1/instances/{id}
338+
339+
# 响应示例(包含TCPS和UDPS字段)
340+
{
341+
"id": "a1b2c3d4",
342+
"alias": "网站代理",
343+
"type": "server",
344+
"status": "running",
345+
"url": "server://0.0.0.0:10101/127.0.0.1:8080",
346+
"restart": true,
347+
"pool": 64,
348+
"ping": 25,
349+
"tcps": 12,
350+
"udps": 5,
351+
"tcprx": 1048576,
352+
"tcptx": 2097152,
353+
"udprx": 512000,
354+
"udptx": 256000
355+
}
356+
357+
# 使用SSE实时监控所有实例状态变化
358+
curl -H "X-API-Key: your-api-key" \
359+
-H "Accept: text/event-stream" \
360+
http://localhost:9090/api/v1/events
361+
```
362+
363+
此监控设置提供:
364+
- **实时连接数跟踪**:TCPS和UDPS字段显示当前活动连接数
365+
- **性能分析**:通过连接数和流量数据评估系统负载
366+
- **容量规划**:基于历史连接数据进行资源规划
367+
- **故障诊断**:异常的连接数变化可能指示网络问题
368+
331369
## 下一步
332370

333371
现在您已经了解了各种使用示例,您可能想要:

docs/zh/how-it-works.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ NodePass 的数据交换机制体现了现代网络编程的最佳实践:
361361
- 实时的字节级流量统计,支持精确的带宽控制
362362
- 分协议的流量分析,便于性能调优
363363
- 连接级别的性能指标,支持细粒度监控
364+
- 实时跟踪TCP和UDP活动连接数,便于容量规划和性能分析
364365

365366
### 协议优化
366367
1. **TCP优化**

0 commit comments

Comments
 (0)