sysstat

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sysstat 采集概览页展示的主机与进程信息:CPU、内存、磁盘、网卡与实时速率。

只读取本机信息(Linux 读取 /proc),不访问任何外部地址。速率与使用率通过相邻两次采样的差值计算, 因此首次调用会额外采样一次。不支持的平台上对应字段留空,由前端显示为“-”。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPU

type CPU struct {
	Model string    `json:"model,omitempty"`
	Cores int       `json:"cores"`
	Usage *float64  `json:"usage,omitempty"`
	Load  []float64 `json:"load,omitempty"`
}

CPU 描述处理器信息。Usage 为整机使用率百分比,未知时为 nil。

type Collector

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

Collector 保存上一次采样,用于计算使用率与速率。并发安全。

func New

func New(dir string) *Collector

New 创建采集器,dir 为统计磁盘容量的目录(一般为配置目录)。

func (*Collector) Snapshot

func (c *Collector) Snapshot() Snapshot

Snapshot 采集一次主机信息。

type Disk

type Disk struct {
	Path  string `json:"path"`
	Total uint64 `json:"total"`
	Used  uint64 `json:"used"`
	Free  uint64 `json:"free"`
}

Disk 描述配置目录所在分区的容量,单位字节。

func DiskUsage added in v0.6.5

func DiskUsage(dir string) *Disk

DiskUsage 返回 dir 所在分区的容量,不支持的平台或读取失败时返回 nil。

type Interface

type Interface struct {
	Name    string   `json:"name"`
	MAC     string   `json:"mac,omitempty"`
	MTU     int      `json:"mtu"`
	IPv4    []string `json:"ipv4"`
	IPv6    []string `json:"ipv6"`
	RxBytes uint64   `json:"rxBytes"`
	TxBytes uint64   `json:"txBytes"`
	RxRate  *float64 `json:"rxRate,omitempty"`
	TxRate  *float64 `json:"txRate,omitempty"`
}

Interface 描述一个网卡。速率单位为字节/秒,未知时为 nil。

type ManagedProcess added in v0.6.5

type ManagedProcess struct {
	proc.Managed
	RSS uint64 `json:"rss,omitempty"`
	// CPU 与 Gately 进程口径一致,按整机核数归一化的百分比
	CPU     *float64 `json:"cpu,omitempty"`
	Threads int      `json:"threads,omitempty"`
}

ManagedProcess 是一个托管进程及其资源占用。只统计该进程本身,不含它再启动的子进程; 取不到的字段为空(不支持的平台、进程刚启动还没有两次采样时的 CPU)。

type Memory

type Memory struct {
	Total     uint64 `json:"total"`
	Used      uint64 `json:"used"`
	Available uint64 `json:"available"`
	SwapTotal uint64 `json:"swapTotal"`
	SwapUsed  uint64 `json:"swapUsed"`
}

Memory 描述物理内存与交换分区,单位字节。

type Process

type Process struct {
	PID        int      `json:"pid"`
	RSS        uint64   `json:"rss,omitempty"`
	CPU        *float64 `json:"cpu,omitempty"`
	Threads    int      `json:"threads,omitempty"`
	FDs        int      `json:"fds,omitempty"`
	Goroutines int      `json:"goroutines"`
	HeapAlloc  uint64   `json:"heapAlloc"`
	HeapSys    uint64   `json:"heapSys"`
	NumGC      uint32   `json:"numGC"`
}

Process 描述 Gately 进程自身的资源占用。

type Snapshot

type Snapshot struct {
	Hostname    string      `json:"hostname"`
	OS          string      `json:"os"`
	Platform    string      `json:"platform,omitempty"`
	Kernel      string      `json:"kernel,omitempty"`
	Arch        string      `json:"arch"`
	InContainer bool        `json:"inContainer"`
	BootTime    int64       `json:"bootTime,omitempty"`
	CPU         CPU         `json:"cpu"`
	Memory      *Memory     `json:"memory,omitempty"`
	Disk        *Disk       `json:"disk,omitempty"`
	Interfaces  []Interface `json:"interfaces"`
	Process     Process     `json:"process"`
	// Managed 为 Gately 托管的外部进程(frpc、tailscaled、File Browser 等)及各自的资源占用
	Managed   []ManagedProcess `json:"managed"`
	SampledAt time.Time        `json:"sampledAt"`
}

Snapshot 是一次采集的结果。

Jump to

Keyboard shortcuts

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