159 lines
4.8 KiB
Markdown
159 lines
4.8 KiB
Markdown
# Go Vehicle Gateway 验证手册
|
||
|
||
本文档用于验证 Go 重构运行面:
|
||
|
||
- `go-vehicle-gateway`:GB32960 TCP、JT808 TCP、宇通 MQTT 接入。
|
||
- `go-history-writer`:Kafka RAW 写 TDengine。
|
||
- `go-stat-writer`:Kafka RAW 写 MySQL 每日指标。
|
||
- `go-realtime-api`:Kafka unified event 写 Redis,并提供实时查询 API。
|
||
|
||
## 本地构建验证
|
||
|
||
```bash
|
||
cd go/vehicle-gateway
|
||
go test ./...
|
||
go build ./cmd/gateway
|
||
go build ./cmd/history-writer
|
||
go build ./cmd/stat-writer
|
||
go build ./cmd/realtime-api
|
||
```
|
||
|
||
## 生产原生部署验证
|
||
|
||
```bash
|
||
python3 tools/go_prod_acceptance.py --date 2026-07-02
|
||
```
|
||
|
||
该命令会聚合执行:
|
||
|
||
- `go_systemd_prod_smoke.py`:应用 ECS systemd 服务 active/enabled、端口归属和 gateway spool
|
||
- `go_kafka_prod_smoke.py`:Kafka topic 和消费组 lag
|
||
- `go_native_prod_smoke.py`:HTTP API、TDengine/MySQL/Redis 数据链路
|
||
|
||
如需单独检查 systemd:
|
||
|
||
```bash
|
||
python3 tools/go_systemd_prod_smoke.py --host 115.29.187.205 --user root
|
||
```
|
||
|
||
脚本通过 SSH 检查:
|
||
|
||
- `lingniu-go-gateway.service`
|
||
- `lingniu-go-history-writer.service`
|
||
- `lingniu-go-stat-writer.service`
|
||
- `lingniu-go-realtime-api.service`
|
||
- 上述服务均为 `active` 且 `enabled`
|
||
- `808`、`32960` 由 `gateway` 监听
|
||
- `20210` 由 `realtime-api` 监听
|
||
- `/opt/lingniu-go-native/spool/gateway` 无待回放文件
|
||
|
||
## 生产环境变量
|
||
|
||
当前 goal 的生产面使用 ECS 原生 systemd 部署,不再以 Docker/Portainer 作为生产运行方式。以下环境变量维护在 `/opt/lingniu-go-native/env/*.env`:
|
||
|
||
```bash
|
||
KAFKA_BROKERS=172.17.111.56:9092
|
||
TDENGINE_DSN=root:<password>@ws(172.17.111.57:6041)/lingniu_vehicle_ts
|
||
MYSQL_DSN=lingniu_vehicle:<password>@tcp(rm-bp179zbv481rnw3e2.mysql.rds.aliyuncs.com:3306)/lingniu_vehicle_data?parseTime=true&charset=utf8mb4,utf8&loc=Asia%2FShanghai
|
||
IDENTITY_MYSQL_DSN=${MYSQL_DSN}
|
||
VEHICLE_IDENTITY_TABLE=vehicle_identity_binding
|
||
REDIS_ADDR=r-bp1u741kij7e51i481.redis.rds.aliyuncs.com:6379
|
||
REDIS_PASSWORD=<password>
|
||
REDIS_DB=50
|
||
```
|
||
|
||
宇通 MQTT 开启时再配置:
|
||
|
||
```bash
|
||
YUTONG_MQTT_ENABLED=true
|
||
YUTONG_MQTT_URI=<mqtt-uri>
|
||
YUTONG_MQTT_TOPICS=/ytforward/shln/+
|
||
YUTONG_MQTT_CLIENT_ID=lingniu-go-yutong-mqtt
|
||
YUTONG_MQTT_USERNAME=<username>
|
||
YUTONG_MQTT_PASSWORD=<password>
|
||
```
|
||
|
||
## ECS 进程检查
|
||
|
||
```bash
|
||
systemctl is-active lingniu-go-gateway lingniu-go-history-writer lingniu-go-stat-writer lingniu-go-realtime-api
|
||
|
||
ss -lntp | egrep ':(808|32960|20210)\b'
|
||
```
|
||
|
||
## Kafka 验证
|
||
|
||
优先使用 smoke 脚本做可重复检查:
|
||
|
||
```bash
|
||
python3 tools/go_kafka_prod_smoke.py --host 114.55.58.251 --user root --max-lag 100
|
||
```
|
||
|
||
脚本会检查 `vehicle.raw.go.gb32960.v1`、`vehicle.raw.go.jt808.v1`、`vehicle.raw.go.yutong-mqtt.v1`、`vehicle.event.go.unified.v1` 是否存在,并汇总 `go-history-writer`、`go-stat-writer`、`go-realtime-api` 的消费 lag。运行环境需要 SSH 免密或已建立可用的 SSH 认证方式。
|
||
|
||
手工核对命令:
|
||
|
||
```bash
|
||
kafka-console-consumer --bootstrap-server 172.17.111.56:9092 \
|
||
--topic vehicle.raw.go.jt808.v1 --max-messages 1 --timeout-ms 10000
|
||
|
||
kafka-console-consumer --bootstrap-server 172.17.111.56:9092 \
|
||
--topic vehicle.raw.go.gb32960.v1 --max-messages 1 --timeout-ms 10000
|
||
|
||
kafka-console-consumer --bootstrap-server 172.17.111.56:9092 \
|
||
--topic vehicle.raw.go.yutong-mqtt.v1 --max-messages 1 --timeout-ms 10000
|
||
|
||
kafka-console-consumer --bootstrap-server 172.17.111.56:9092 \
|
||
--topic vehicle.event.go.unified.v1 --max-messages 1 --timeout-ms 10000
|
||
|
||
kafka-consumer-groups --bootstrap-server 172.17.111.56:9092 \
|
||
--describe --group go-history-writer
|
||
|
||
kafka-consumer-groups --bootstrap-server 172.17.111.56:9092 \
|
||
--describe --group go-stat-writer
|
||
|
||
kafka-consumer-groups --bootstrap-server 172.17.111.56:9092 \
|
||
--describe --group go-realtime-api
|
||
```
|
||
|
||
## TDengine 验证
|
||
|
||
```sql
|
||
USE lingniu_vehicle_ts;
|
||
SHOW STABLES;
|
||
SELECT COUNT(*) FROM raw_frames;
|
||
SELECT COUNT(*) FROM vehicle_locations;
|
||
SELECT COUNT(*) FROM vehicle_mileage_points;
|
||
```
|
||
|
||
## MySQL 验证
|
||
|
||
```sql
|
||
SELECT protocol, metric_key, COUNT(*)
|
||
FROM vehicle_daily_metric
|
||
GROUP BY protocol, metric_key;
|
||
|
||
SELECT *
|
||
FROM vehicle_daily_metric
|
||
WHERE metric_key IN ('daily_mileage_km', 'daily_total_mileage_km')
|
||
ORDER BY updated_at DESC
|
||
LIMIT 20;
|
||
```
|
||
|
||
## Redis 实时查询
|
||
|
||
```bash
|
||
curl -sS 'http://115.29.187.205:20210/api/realtime/vehicles/<vin>'
|
||
curl -sS 'http://115.29.187.205:20210/api/realtime/vehicles/<vin>/online'
|
||
curl -sS 'http://115.29.187.205:20210/api/realtime/vehicles/<vin>/protocols/JT808'
|
||
```
|
||
|
||
## 验收证据
|
||
|
||
正式切换前至少记录:
|
||
|
||
- 一个真实 GB32960 VIN 的 RAW、location、mileage point、Redis snapshot。
|
||
- 一个真实 JT808 VIN/phone 的 RAW、location、mileage point、daily metric、Redis snapshot。
|
||
- 一个真实宇通 MQTT VIN 或 device_id 的 RAW、Redis snapshot。
|
||
- `go-history-writer` 和 `go-stat-writer` 重启后 Kafka offset 能继续推进。
|