v2

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 2 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"
)
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 {
	Up        int64 `json:"up"`
	Down      int64 `json:"down"`
	TotalUp   int64 `json:"totalUp"`
	TotalDown int64 `json:"totalDown"`
}

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"`
	FinishedAt time.Time `json:"finished_at"`
	// Role 为空表示主目标;"reference" 表示这是参考点的结果。
	Role string `json:"role,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 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"`
}

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 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"`
}

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

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

Jump to

Keyboard shortcuts

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