docs(agent): 统一中文注释并补充部署文档

将代码与测试注释改为中文以符合仓库规范;新增中文部署指南、
示例配置,并完善构建脚本对 VERSION 注入的说明。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
codex
2026-05-19 02:30:49 +00:00
parent 89d5e27874
commit 877e4cf41d
28 changed files with 608 additions and 226 deletions

View File

@@ -2,9 +2,9 @@ package status
import "time"
// HostStatus is the full cached host snapshot returned by /status and posted by the reporter.
// HostStatus 是 /status 返回的完整缓存主机快照,也是上报器 POST 的载荷结构。
type HostStatus struct {
// Agent describes the agent process and most recent snapshot metadata.
// Agent 描述 agent 进程及最近一次快照的元数据。
Agent AgentInfo `json:"agent"`
Host HostInfo `json:"host"`
Network NetworkInfo `json:"network"`
@@ -13,31 +13,31 @@ type HostStatus struct {
Disks []DiskInfo `json:"disks"`
Processes ProcessResult `json:"processes"`
TCPListeners TCPResult `json:"tcp_listeners"`
// Errors records collector-level failures that caused a partial snapshot.
// Errors 记录导致快照变为 partial 的子采集器失败信息。
Errors []StatusError `json:"errors"`
}
// AgentInfo contains agent process metadata and the latest collection result.
// AgentInfo 包含 agent 进程元数据及最近一次采集结果。
type AgentInfo struct {
Version string `json:"version"`
StartedAt time.Time `json:"started_at"`
SnapshotAt time.Time `json:"snapshot_at"`
// SnapshotStatus is ok when all collectors succeed and partial when one or more fail.
// SnapshotStatus 在所有采集器成功时为 ok,任一失败时为 partial。
SnapshotStatus string `json:"snapshot_status"`
}
// HostInfo describes the monitored host identity and operating system.
// HostInfo 描述被监控主机的标识与操作系统信息。
type HostInfo struct {
HostID string `json:"host_id"`
Hostname string `json:"hostname"`
Platform string `json:"platform"`
PlatformVersion string `json:"platform_version"`
Arch string `json:"arch"`
// UptimeSeconds is the host uptime in seconds when available.
// UptimeSeconds 为主机运行时长(秒),在可用时填充。
UptimeSeconds uint64 `json:"uptime_seconds"`
}
// NetworkInfo contains all network interfaces plus flattened IPv4, IPv6, and MAC lists.
// NetworkInfo 包含全部网卡及展平后的 IPv4、IPv6、MAC 列表。
type NetworkInfo struct {
Interfaces []NetworkInterface `json:"interfaces"`
IPv4s []string `json:"ipv4s"`
@@ -45,67 +45,67 @@ type NetworkInfo struct {
MACs []string `json:"macs"`
}
// NetworkInterface describes one host network interface and its configured addresses.
// NetworkInterface 描述一块网卡及其配置的地址。
type NetworkInterface struct {
Name string `json:"name"`
MAC string `json:"mac"`
// MTU is the interface maximum transmission unit in bytes.
// MTU 为接口最大传输单元(字节)。
MTU int `json:"mtu"`
Flags []string `json:"flags"`
Addresses []string `json:"addresses"`
}
// CPUInfo describes host CPU capacity and current utilization.
// CPUInfo 描述主机 CPU 容量与当前利用率。
type CPUInfo struct {
LogicalCores int `json:"logical_cores"`
PhysicalCores int `json:"physical_cores"`
// UsagePercent is the best-effort host CPU usage percentage for the latest collection.
// UsagePercent 为最近一次采集得到的尽力主机 CPU 使用率(百分比)。
UsagePercent float64 `json:"usage_percent"`
LoadAvg []float64 `json:"load_avg"`
ModelName string `json:"model_name"`
}
// MemoryInfo describes host memory usage capacity fields in the declared unit.
// MemoryInfo 描述主机内存容量与使用情况,数值单位由 Unit 字段声明。
type MemoryInfo struct {
// Unit declares the unit used by total, used, free, and available.
// Unit 声明 total、used、free、available 使用的单位。
Unit string `json:"unit"`
// Total is total physical memory in the declared unit.
// Total 为物理内存总量(与 Unit 一致)。
Total uint64 `json:"total"`
// Used is memory currently used in the declared unit.
// Used 为当前已用内存(与 Unit 一致)。
Used uint64 `json:"used"`
// Free is memory currently free in the declared unit.
// Free 为当前空闲内存(与 Unit 一致)。
Free uint64 `json:"free"`
// Available is memory available to new workloads in the declared unit.
// Available 为可供新负载使用的内存(与 Unit 一致)。
Available uint64 `json:"available"`
// UsedPercent is the percentage of total memory currently used.
// UsedPercent 为已用内存占总量的百分比。
UsedPercent float64 `json:"used_percent"`
}
// DiskInfo describes one physical or network mounted filesystem and its capacity.
// DiskInfo 描述一块已挂载文件系统的容量与使用情况。
type DiskInfo struct {
Device string `json:"device"`
MountPoint string `json:"mount_point"`
FSType string `json:"fs_type"`
// Unit declares the unit used by total, used, and free.
// Unit 声明 total、used、free 使用的单位。
Unit string `json:"unit"`
// Total is filesystem capacity in the declared unit.
// Total 为文件系统总容量(与 Unit 一致)。
Total uint64 `json:"total"`
// Used is consumed filesystem capacity in the declared unit.
// Used 为已占用容量(与 Unit 一致)。
Used uint64 `json:"used"`
// Free is available filesystem capacity in the declared unit.
// Free 为可用容量(与 Unit 一致)。
Free uint64 `json:"free"`
// UsedPercent is the percentage of total filesystem capacity currently used.
// UsedPercent 为已用容量占总量的百分比。
UsedPercent float64 `json:"used_percent"`
}
// ProcessResult contains process collection status and the collected process list.
// ProcessResult 包含进程采集状态及进程列表。
type ProcessResult struct {
// Status is ok, partial, or error depending on process collection completeness.
// Status 根据进程采集完整程度为 ok、partial 或 error。
Status string `json:"status"`
Items []ProcessInfo `json:"items"`
}
// ProcessInfo describes one operating system process.
// ProcessInfo 描述一个操作系统进程。
type ProcessInfo struct {
PID int `json:"pid"`
PPID int `json:"ppid"`
@@ -114,24 +114,24 @@ type ProcessInfo struct {
Cmdline string `json:"cmdline"`
Username string `json:"username"`
Status string `json:"status"`
// StartTime is the platform-specific process start timestamp when available.
// StartTime 为平台相关的进程启动时间戳,在可用时填充。
StartTime int64 `json:"start_time"`
// CPUPercent is the best-effort process CPU usage percentage.
// CPUPercent 为尽力估算的进程 CPU 使用率(百分比)。
CPUPercent float64 `json:"cpu_percent"`
// MemoryRSS is resident memory size in bytes.
// MemoryRSS 为常驻内存大小(字节)。
MemoryRSS uint64 `json:"memory_rss"`
// MemoryVMS is virtual memory size in bytes.
// MemoryVMS 为虚拟内存大小(字节)。
MemoryVMS uint64 `json:"memory_vms"`
}
// TCPResult contains TCP listener collection status and listener entries.
// TCPResult 包含 TCP 监听采集状态及监听项列表。
type TCPResult struct {
// Status is ok, partial, or error depending on listener mapping completeness.
// Status 根据监听端口到进程映射的完整程度为 ok、partial 或 error。
Status string `json:"status"`
Items []TCPListenerInfo `json:"items"`
}
// TCPListenerInfo describes one listening TCP socket and its owning process when known.
// TCPListenerInfo 描述一个处于监听状态的 TCP 套接字及所属进程(若已知)。
type TCPListenerInfo struct {
IP string `json:"ip"`
Port int `json:"port"`
@@ -141,7 +141,7 @@ type TCPListenerInfo struct {
Family string `json:"family"`
}
// StatusError records a collector failure without failing the whole snapshot.
// StatusError 记录单个子采集器失败,不导致整份快照请求失败。
type StatusError struct {
Collector string `json:"collector"`
Message string `json:"message"`