v2

package
v1.7.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version               = "2.0"
	MethodAgentReport     = "agent.report"
	MethodAgentBasicInfo  = "agent.basicInfo"
	MethodAgentPingResult = "agent.pingResult"
	MethodAgentTaskResult = "agent.taskResult"
	MethodAgentExec       = "agent.exec"
	MethodAgentPing       = "agent.ping"
	MethodAgentMessage    = "agent.message"
	MethodAgentEvent      = "agent.event"
	MethodAgentTerminal   = "agent.terminal.request"
	MethodAgentPull       = "agent.pull"
	MethodAgentFile       = "agent.file"
	MethodAgentFileResult = "agent.file.result"
	MethodAgentUnlock     = "agent.unlock"
	// MethodAgentUpdate 让面板指定一个节点要运行的版本(roadmap H6)。
	//
	// 这份文件与 agent/protocol/v2/jsonrpc.go 是同一协议的两份副本(面板与 agent 是两个模块,无法共享
	// 代码),手工保持同步 —— 两侧各有一个测试断言方法名集合一致,否则漂移只会表现为「事件发出去了但
	// agent 说 unknown method」。
	MethodAgentUpdate = "agent.update"
)
View Source
const (
	MethodNetworkTestNextTrace       = "networkTest.nextTrace"
	MethodNetworkTestIperf3          = "networkTest.iperf3"
	MethodNetworkTestMeshTrace       = "networkTest.meshTrace"
	MethodNetworkTestGetMeshTraceJob = "networkTest.getMeshTraceJob"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BackupReport

type BackupReport struct {
	// AgeSeconds 距最后一次【成功】备份的秒数;-1 表示无法确定
	//(状态文件缺失或不可解析),此时 Ok 必为 0。
	AgeSeconds int64 `json:"age_seconds"`
	// Ok 为 1 表示最近一次备份成功,0 表示失败或状态未知。
	Ok int `json:"ok"`
	// Message 是可选的人类可读说明(例如失败原因),便于排查。
	Message string `json:"message,omitempty"`
}

BackupReport 是备份新鲜度上报。

动机:备份「有没有在跑」和「最后一次成功是什么时候」往往没有人看, 直到真需要恢复时才发现已经坏了几个月。把最后成功时间变成可监控的指标, 就能用与主机指标相同的方式设阈值/基线告警。

type BasicInfoParams

type BasicInfoParams struct {
	Info map[string]interface{} `json:"info"`
}

type CPUReport

type CPUReport struct {
	Name  string  `json:"name,omitempty"`
	Cores int     `json:"cores,omitempty"`
	Arch  string  `json:"arch,omitempty"`
	Usage float64 `json:"usage,omitempty"`
}

type ConnectionsReport

type ConnectionsReport struct {
	TCP int `json:"tcp"`
	UDP int `json:"udp"`
}

type DiskReport

type DiskReport struct {
	Total int64 `json:"total"`
	Used  int64 `json:"used"`
}

type Event

type Event struct {
	ID        string    `json:"id"`
	Method    string    `json:"method"`
	Params    any       `json:"params,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

type EventParams

type EventParams struct {
	Type string `json:"type"`
	Data any    `json:"data,omitempty"`
}

type ExecParams

type ExecParams struct {
	TaskID  string `json:"task_id"`
	Command string `json:"command"`
}

type FileOperation

type FileOperation struct {
	UUID      string         `json:"uuid"`
	RequestID string         `json:"request_id"`
	Op        string         `json:"op"`
	Args      map[string]any `json:"args,omitempty"`
}

FileOperation is metadata-only. File contents travel through the dedicated HTTP transfer endpoint rather than through JSON-RPC.

type FileResult

type FileResult struct {
	UUID      string          `json:"uuid"`
	RequestID string          `json:"request_id"`
	OK        bool            `json:"ok"`
	Result    json.RawMessage `json:"result,omitempty"`
	Error     string          `json:"error,omitempty"`
}

type GPUDetailReport

type GPUDetailReport struct {
	Count        int             `json:"count"`
	AverageUsage float64         `json:"average_usage"`
	DetailedInfo []GPUDeviceInfo `json:"detailed_info"`
}

type GPUDeviceInfo

type GPUDeviceInfo struct {
	Name        string  `json:"name"`
	MemoryTotal int64   `json:"memory_total"`
	MemoryUsed  int64   `json:"memory_used"`
	Utilization float64 `json:"utilization"`
	Temperature int     `json:"temperature"`
}

type IPAddress

type IPAddress struct {
	Ipv4 string `json:"ipv4"`
	Ipv6 string `json:"ipv6"`
}

type IPFamily

type IPFamily string
const (
	IPFamilyAuto IPFamily = "auto"
	IPFamilyIPv4 IPFamily = "ipv4"
	IPFamilyIPv6 IPFamily = "ipv6"
)

type LoadReport

type LoadReport struct {
	Load1  float64 `json:"load1"`
	Load5  float64 `json:"load5"`
	Load15 float64 `json:"load15"`
}

type MeshMode

type MeshMode string
const (
	MeshModeAllToAll MeshMode = "all_to_all"
	MeshModeOneToAll MeshMode = "one_to_all"
	MeshModePairs    MeshMode = "pairs"
)

type MeshTraceAccepted

type MeshTraceAccepted struct {
	JobID          string    `json:"job_id"`
	Status         string    `json:"status"`
	TotalPairs     int       `json:"total_pairs"`
	AcceptedAt     time.Time `json:"accepted_at"`
	PollIntervalMs int       `json:"poll_interval_ms"`
}

type MeshTraceJobSnapshot

type MeshTraceJobSnapshot struct {
	JobID      string            `json:"job_id"`
	Status     string            `json:"status"`
	Total      int               `json:"total"`
	Done       int               `json:"done"`
	Failed     int               `json:"failed"`
	Running    int               `json:"running"`
	Results    []NextTraceResult `json:"results"`
	StartedAt  time.Time         `json:"started_at"`
	UpdatedAt  time.Time         `json:"updated_at"`
	FinishedAt *time.Time        `json:"finished_at"`
	Error      string            `json:"error"`
}

type MeshTraceParams

type MeshTraceParams struct {
	SourceNodeIDs  []string      `json:"source_node_ids"`
	TargetNodeIDs  []string      `json:"target_node_ids"`
	Mode           MeshMode      `json:"mode"`
	IPFamily       IPFamily      `json:"ip_family"`
	Protocol       TraceProtocol `json:"protocol"`
	MaxHops        int           `json:"max_hops"`
	TimeoutMs      int           `json:"timeout_ms"`
	MaxConcurrency int           `json:"max_concurrency"`
	PerAgentLimit  int           `json:"per_agent_limit"`
}

type Message

type Message struct {
	Type      string `json:"type"`
	Content   string `json:"content"`
	Sender    string `json:"sender"`
	Timestamp int64  `json:"timestamp"`
}

type MessageParams

type MessageParams struct {
	Type    string `json:"type"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

type NetworkReport

type NetworkReport struct {
	TCPRetransPercent *float64 `json:"tcp_retrans_percent,omitempty"`
	Up                int64    `json:"up"`
	Down              int64    `json:"down"`
	// TotalUp / TotalDown 是内核自开机以来的累计字节数:单调,可以做差得到"这段时间用了多少"。
	TotalUp   int64 `json:"totalUp"`
	TotalDown int64 `json:"totalDown"`
	// CycleUp / CycleDown 是自计费周期重置日以来的累计流量(--month-rotate)。
	//
	// 它**不是**计数器:跨周期会归零。面板必须按 gauge 存它的最后值,而不是对采样求和
	// (求和等于"累计值 × 采样次数"),也不要对它取差值(那会把整个累计当增量)。
	CycleUp   int64 `json:"cycleUp,omitempty"`
	CycleDown int64 `json:"cycleDown,omitempty"`
}

type NextTraceParams

type NextTraceParams struct {
	TaskID     string        `json:"task_id"`
	SourceID   string        `json:"source_id"`
	TargetID   string        `json:"target_id"`
	TargetHost string        `json:"target_host"`
	IPFamily   IPFamily      `json:"ip_family"`
	Protocol   TraceProtocol `json:"protocol"`
	MaxHops    int           `json:"max_hops"`
	TimeoutMs  int           `json:"timeout_ms"`
	RawOutput  bool          `json:"raw_output"`
}

type NextTraceResult

type NextTraceResult struct {
	TaskID     string          `json:"task_id"`
	SourceID   string          `json:"source_id"`
	TargetID   string          `json:"target_id"`
	TargetHost string          `json:"target_host"`
	IPFamily   IPFamily        `json:"ip_family"`
	Protocol   TraceProtocol   `json:"protocol"`
	StartedAt  time.Time       `json:"started_at"`
	FinishedAt time.Time       `json:"finished_at"`
	DurationMs int             `json:"duration_ms"`
	OK         bool            `json:"ok"`
	Error      string          `json:"error"`
	Summary    TraceSummary    `json:"summary"`
	Hops       []TraceHop      `json:"hops"`
	Raw        json.RawMessage `json:"raw"`
	RawText    string          `json:"raw_text"`
	ExitCode   int             `json:"exit_code"`
	Truncated  bool            `json:"truncated"`
}

type NodeEndpoint

type NodeEndpoint struct {
	NodeID string   `json:"node_id"`
	Name   string   `json:"name"`
	Host   string   `json:"host"`
	Family IPFamily `json:"ip_family"`
}

type PingParams

type PingParams struct {
	TaskID uint   `json:"ping_task_id"`
	Type   string `json:"ping_type"`
	Target string `json:"ping_target"`
	// Reference 非空时,agent 会在同一周期额外探测该目标,
	// 并以 role="reference" 上报,用于主机 vs 网关的路径归因。
	Reference string `json:"ping_reference,omitempty"`
}

type PingResultParams

type PingResultParams struct {
	TaskID   uint   `json:"task_id"`
	PingType string `json:"ping_type"`
	Value    int    `json:"value"`
	// ValueUS 是同一测量结果的微秒精度值(新 agent 上报的 value_us)。
	//
	// 旧 agent 不发这个字段,此时为 0,面板回退到 Value(整数毫秒)。落库形态不变:
	// 仍然写 ping.latency_ms 这一条序列,只是值从整数毫秒变成小数毫秒
	// (420 µs → 0.42 ms)—— 不新增指标、不新增标签、不新增序列。
	ValueUS    int64     `json:"value_us,omitempty"`
	FinishedAt time.Time `json:"finished_at"`
	// Role 为空表示主目标;"reference" 表示这是参考点的结果。
	Role string `json:"role,omitempty"`
	// Family 是本次测量实际使用的地址族("ipv4"/"ipv6")。
	// 目标是域名时由各节点自行解析,双栈域名可能落到不同族;面板靠它把
	// 「同一任务、不同路径」拆成两条序列。旧 agent 不发该字段,此时为空,
	// 行为与改动前完全一致。
	Family string `json:"family,omitempty"`
}

type PullParams

type PullParams struct {
	Capabilities []string `json:"capabilities,omitempty"`
	AckEventIDs  []string `json:"ack_event_ids,omitempty"`
	LastEventID  string   `json:"last_event_id,omitempty"`
}

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

type RamReport

type RamReport struct {
	Total int64 `json:"total"`
	Used  int64 `json:"used"`
}

type RawRequest added in v0.1.16

type RawRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
	ID      any             `json:"id,omitempty"`
}

RawRequest is the wire shape of one inbound JSON-RPC request whose params have not been decoded yet.

The panel has to hand the params to a method-specific struct. Decoding them through Request.Params (an untyped `any`) builds a map[string]any for the whole payload — every number, nested object and string — only to marshal it back to JSON and unmarshal it into the typed struct. RawRequest keeps the params as the bytes that arrived, so the payload is decoded exactly once, by the code that knows what it is.

Request itself is unchanged: it is the shape this protocol uses when the panel *builds* a message (web/agent, web/rpc/jsonrpc), where the params are Go values that still have to be marshalled onto the wire.

func (RawRequest) DecodeParams added in v0.1.16

func (r RawRequest) DecodeParams(target any) error

DecodeParams unmarshals the request params into target.

Params are optional in JSON-RPC, and an omitted or explicitly null value leaves target untouched and reports no error, so method defaults keep applying exactly as they did when the params travelled through an untyped map.

type Report

type Report struct {
	UUID        string            `json:"uuid,omitempty"`
	CPU         CPUReport         `json:"cpu"`
	Ram         RamReport         `json:"ram"`
	Swap        RamReport         `json:"swap"`
	Load        LoadReport        `json:"load"`
	Disk        DiskReport        `json:"disk"`
	Network     NetworkReport     `json:"network"`
	Connections ConnectionsReport `json:"connections"`
	GPU         *GPUDetailReport  `json:"gpu,omitempty"`
	Uptime      int64             `json:"uptime"`
	Process     int               `json:"process"`
	// Backup 是可选的备份新鲜度上报。agent 未配置备份状态文件时为 nil,
	// 因此不影响未使用该功能的部署,也不会写入任何 point。
	Backup                *BackupReport     `json:"backup,omitempty"`
	Message               string            `json:"message"`
	Method                string            `json:"method,omitempty"`
	UpdatedAt             time.Time         `json:"updated_at"`
	SampledAt             time.Time         `json:"sampled_at,omitempty"`
	ReceivedAt            time.Time         `json:"received_at,omitempty"`
	SampleIntervalSeconds float64           `json:"sample_interval_seconds,omitempty"`
	CounterEpoch          string            `json:"counter_epoch,omitempty"`
	Quality               map[string]string `json:"quality,omitempty"`
}

func (Report) BoundedPayload added in v0.1.13

func (r Report) BoundedPayload() bool

BoundedPayload limits retained strings and GPU cardinality before queueing.

type ReportParams

type ReportParams struct {
	Report      Report   `json:"report"`
	AckEventIDs []string `json:"ack_event_ids,omitempty"`
}

type Request

type Request struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	Params  any    `json:"params,omitempty"`
	ID      any    `json:"id,omitempty"`
}

type Response

type Response struct {
	JSONRPC string    `json:"jsonrpc"`
	ID      any       `json:"id,omitempty"`
	Result  any       `json:"result,omitempty"`
	Error   *RPCError `json:"error,omitempty"`
}

func Error

func Error(id any, code int, message string, data any) Response

func Success

func Success(id any, result any) Response

type RouteItem added in v1.6.13

type RouteItem struct {
	Carrier string `json:"carrier"`
	Target  string `json:"target"`
	Label   string `json:"label"`
	Reached bool   `json:"reached"`
	Hops    int    `json:"hops"`
	Error   string `json:"error,omitempty"`
}

type TaskResultParams

type TaskResultParams struct {
	TaskID     string    `json:"task_id"`
	Result     string    `json:"result"`
	ExitCode   int       `json:"exit_code"`
	FinishedAt time.Time `json:"finished_at"`
}

type TerminalRequestParams

type TerminalRequestParams struct {
	RequestID string `json:"request_id"`
}

type TraceHop

type TraceHop struct {
	Hop      int     `json:"hop"`
	Host     string  `json:"host"`
	IP       string  `json:"ip"`
	RTTMs    float64 `json:"rtt_ms"`
	Loss     float64 `json:"loss"`
	ASN      string  `json:"asn"`
	Location string  `json:"location"`
}

type TraceProtocol

type TraceProtocol string
const (
	TraceProtocolICMP TraceProtocol = "icmp"
	TraceProtocolTCP  TraceProtocol = "tcp"
	TraceProtocolUDP  TraceProtocol = "udp"
)

type TraceSummary

type TraceSummary struct {
	HopCount   int     `json:"hop_count"`
	Reached    bool    `json:"reached"`
	PacketLoss float64 `json:"packet_loss"`
	RTTMs      float64 `json:"rtt_ms"`
}

type UnlockItem added in v0.1.9

type UnlockItem struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Kind   string `json:"kind"`
	Status string `json:"status"`
	Region string `json:"region,omitempty"`
	Basis  string `json:"basis"`
	Detail string `json:"detail,omitempty"`
}

UnlockItem 是单个服务的结论。字段与 agent/unlock.Result 一一对应;服务端与探针是 两个独立模块,所以这里重新声明而不是共享类型 —— 线上形状就是这个结构体。

type UnlockParams added in v0.1.9

type UnlockParams struct {
	EgressIP       string       `json:"egress_ip,omitempty"`
	EgressRegion   string       `json:"egress_region,omitempty"`
	ProbedAt       time.Time    `json:"probed_at"`
	Results        []UnlockItem `json:"results"`
	Routes         []RouteItem  `json:"routes,omitempty"`
	RoutesProbedAt time.Time    `json:"routes_probed_at,omitempty"`
}

UnlockParams 是 agent.unlock 的负载:探针从自己的出口测得的解锁结论。

为什么由探针测而不是服务端测:解锁取决于【发起请求的那个 IP】,服务端在别的机房, 只能测到它自己。出口地址随结果一起上来,因为它不总是节点自己的地址 —— 本机群里 有主机是经由另一台节点出网的。

type UpdateParams added in v0.1.42

type UpdateParams struct {
	Target string `json:"target"`
}

UpdateParams 是一次指定版本升级的请求,或一次取消。Target 为空表示取消指定、回到跟随最新发布。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL