collector

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package collector 采集节点系统信息(Linux /proc,零外部依赖)。 生产 Agent 部署在 Linux systemd 环境,无需跨平台。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector 通过 /proc 采集。

func New

func New() *Collector

New 构造采集器。

func (*Collector) Close added in v0.1.18

func (c *Collector) Close()

Close 停止后台高频采样。

func (*Collector) RealtimeSnapshot added in v0.3.1

func (c *Collector) RealtimeSnapshot() Snapshot

RealtimeSnapshot 采集实时差分指标(CPU 为自上次调用以来的均值,网速结合瞬时/峰值防稀释), 并附带绝对值类指标。它是 CPU 与网速差分基线**唯一**的写入方。

func (*Collector) Snapshot

func (c *Collector) Snapshot() Snapshot

Snapshot 兼容入口:一次取全体指标。旧主控(未协商快车道)下心跳仍用它, 此时它是唯一的差分写入方,行为与拆分前一致。

func (*Collector) SystemSnapshot added in v0.3.1

func (c *Collector) SystemSnapshot() Snapshot

SystemSnapshot 只采集绝对值类指标(内存 / 磁盘 / 连接数),不碰任何差分基线。

快车道(metrics_split)模式下心跳走这里:CPU 与网速的差分基线只允许 RealtimeSnapshot 一个写入方。两个循环共用一个基线时,后到的一方窗口被压缩到 亚毫秒,量化误差会产出 100% / 0% 的伪值(见 minDeltaWindow)。

type Snapshot

type Snapshot struct {
	CPU       float64 // 百分比(自上次采集以来的均值)
	Mem       float64 // 已用内存(字节)
	MemTotal  float64 // 总内存(字节)
	Disk      float64 // 已用磁盘(字节)
	DiskTotal float64 // 总磁盘(字节)
	RxBytes   uint64  // 物理网卡接收总字节
	TxBytes   uint64  // 物理网卡发送总字节
	RxRate    float64 // 入口带宽速率(字节/秒)
	TxRate    float64 // 出口带宽速率(字节/秒)

	// 连接数(整机口径,读内核连接表;非 Linux 平台 ConnOK=false 表示不支持)
	ConnTCPEstablished int  // TCP 已建立连接数
	ConnTCPTotal       int  // TCP 表项总数(不含 LISTEN,含 TIME_WAIT 等残留)
	ConnUDP            int  // UDP 绑定 socket 数(不是会话数)
	ConnOK             bool // 本平台是否支持采集连接数
}

Snapshot 一次采集结果。

Jump to

Keyboard shortcuts

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