Documentation
¶
Overview ¶
Package metrics provides read-only Linux system telemetry snapshots.
Index ¶
- Variables
- func ValidateProcessIdentity(identity ProcessIdentity) error
- type BatterySnapshot
- type BatteryState
- type BlockDevice
- type BlockRates
- type BlockSampler
- type BlockSnapshot
- type CPUCore
- type CPUSampler
- type CPUSnapshot
- type CPUUsage
- type Capacity
- type Filesystem
- type FilesystemSnapshot
- type GPU
- type GPUSampler
- type GPUSnapshot
- type GPUUsage
- type Issue
- type MemorySnapshot
- type NetworkInterface
- type NetworkRates
- type NetworkSampler
- type NetworkSnapshot
- type Process
- type ProcessIdentity
- type ProcessSampler
- type ProcessSnapshot
- type ThermalSnapshot
- type UptimeSnapshot
Constants ¶
This section is empty.
Variables ¶
var ErrProcessIdentityChanged = errors.New("process identity changed")
ErrProcessIdentityChanged means a PID now identifies a different process.
Functions ¶
func ValidateProcessIdentity ¶ added in v0.4.0
func ValidateProcessIdentity(identity ProcessIdentity) error
ValidateProcessIdentity confirms that identity still names the same process.
Types ¶
type BatterySnapshot ¶ added in v0.2.0
type BatterySnapshot struct {
CollectedAt time.Time
Present bool
Charge float64 // 0..1
ChargeValid bool
State BatteryState
EnergyJoules float64
RateWatts float64
RateValid bool
TimeRemaining time.Duration
TimeValid bool
Issues []Issue
}
BatterySnapshot is the aggregate battery observation. Present is false on a machine with no battery; that is not an error.
func ReadBattery ¶ added in v0.2.0
func ReadBattery() (BatterySnapshot, error)
ReadBattery collects the current aggregate battery. It prefers sysfs power-supply devices of type Battery or UPS. A machine with none reports Present false.
type BatteryState ¶ added in v0.2.0
type BatteryState uint8
BatteryState is the charging state of the aggregate battery.
const ( BatteryUnknown BatteryState = iota BatteryCharging BatteryDischarging BatteryFull )
type BlockDevice ¶
type BlockDevice struct {
Name string
Major uint32
Minor uint32
ReadBytes uint64
WriteBytes uint64
ReadOperations uint64
WriteOperations uint64
Busy time.Duration
Rates BlockRates
}
BlockDevice contains cumulative counters and derived rates for one block device.
type BlockRates ¶
type BlockRates struct {
ReadBytesPerSecond float64
WriteBytesPerSecond float64
ReadOperationsPerSecond float64
WriteOperationsPerSecond float64
BusyFraction float64
Valid bool
}
BlockRates contains rates derived from two block-device observations. Valid distinguishes observed zero rates from unavailable derived values.
type BlockSampler ¶
type BlockSampler struct {
// contains filtered or unexported fields
}
BlockSampler retains previous block counters for sequential rate sampling.
func NewBlockSampler ¶
func NewBlockSampler() *BlockSampler
NewBlockSampler returns a block sampler owned by one sequential polling caller.
func (*BlockSampler) Sample ¶
func (s *BlockSampler) Sample() (BlockSnapshot, error)
Sample returns one block-device snapshot. The sampler is not safe for concurrent use.
type BlockSnapshot ¶
type BlockSnapshot struct {
CollectedAt time.Time
Devices []BlockDevice
Issues []Issue
}
BlockSnapshot contains block-device data collected at one time. Devices and Issues are caller-owned snapshot slices.
type CPUSampler ¶
type CPUSampler struct {
// contains filtered or unexported fields
}
CPUSampler retains the previous CPU counters for sequential rate sampling.
func NewCPUSampler ¶
func NewCPUSampler() *CPUSampler
NewCPUSampler returns a CPU sampler owned by one sequential polling caller.
func (*CPUSampler) Sample ¶
func (s *CPUSampler) Sample() (CPUSnapshot, error)
Sample returns one CPU snapshot. The sampler is not safe for concurrent use.
type CPUSnapshot ¶
type CPUSnapshot struct {
CollectedAt time.Time
Usage CPUUsage
Cores []CPUCore
Load1 float64
Load5 float64
Load15 float64
LoadValid bool
Issues []Issue
}
CPUSnapshot contains aggregate and per-core CPU data collected at one time. Cores and Issues are caller-owned snapshot slices.
type CPUUsage ¶
CPUUsage contains a utilization fraction. Valid distinguishes an observed zero from no sample.
type Filesystem ¶
type Filesystem struct {
MountID uint64
MountPoint string
Source string
Type string
ReadOnly bool
Capacity Capacity
}
Filesystem contains one mounted filesystem and its byte capacity.
type FilesystemSnapshot ¶
type FilesystemSnapshot struct {
CollectedAt time.Time
Filesystems []Filesystem
Issues []Issue
}
FilesystemSnapshot contains mounted filesystem data collected at one time. Filesystems and Issues are caller-owned snapshot slices.
func ReadFilesystems ¶
func ReadFilesystems() (FilesystemSnapshot, error)
ReadFilesystems returns one mounted-filesystem snapshot from Linux. Autofs trigger points are not reported: statfs on a trigger fires the automount, and anything mounted on top has its own mountinfo row.
type GPU ¶ added in v0.3.0
type GPU struct {
PCIID string
Driver string
Name string
Usage GPUUsage
Celsius float64
TempValid bool
// VRAM is dedicated device memory. VRAMValid is false when the driver
// does not report both used and total; an integrated part's shared
// system memory is never counted here.
VRAM Capacity
VRAMValid bool
}
GPU is one display device.
type GPUSampler ¶ added in v0.5.0
type GPUSampler struct {
// contains filtered or unexported fields
}
GPUSampler retains Intel i915 PMU engine counters and DRM client fdinfo baselines for sequential rate sampling. It is owned by one sequential polling caller, starts no goroutines, and owns open PMU counters until Close. ReadGPU cannot report Intel usage; a consumer that needs it must sample here and close the sampler when its polling stops.
Without the privilege the PMU needs, usage for a GPU still lacking it comes from walking /proc for this user's /dev/dri descriptors: one readlink per descriptor each sample, and only while some GPU lacks usage. Other users' clients are invisible to that walk, so usage can stay invalid.
func NewGPUSampler ¶ added in v0.5.0
func NewGPUSampler() *GPUSampler
NewGPUSampler returns a GPU sampler owned by one sequential polling caller. It reports the same snapshot as ReadGPU and additionally fills Intel i915 usage, and usage for any GPU the other paths leave empty, from the second sample on (PMU counters, else DRM client fdinfo).
func (*GPUSampler) Close ¶ added in v0.5.0
func (s *GPUSampler) Close() error
Close closes every open PMU counter and drops sampling state. It is idempotent; sampling after Close starts from a fresh baseline.
func (*GPUSampler) Sample ¶ added in v0.5.0
func (s *GPUSampler) Sample() (GPUSnapshot, error)
Sample returns one GPU snapshot. The sampler is not safe for concurrent use.
type GPUSnapshot ¶ added in v0.3.0
GPUSnapshot lists GPUs collected at one time. GPUs and Issues are caller-owned.
func ReadGPU ¶ added in v0.3.0
func ReadGPU() (GPUSnapshot, error)
ReadGPU collects usage and temperature for each discrete or integrated GPU.
type GPUUsage ¶ added in v0.3.0
GPUUsage is a 0..1 busy fraction. Valid distinguishes a real zero from no sample.
type MemorySnapshot ¶
MemorySnapshot contains memory and swap byte capacities collected at one time.
func ReadMemory ¶
func ReadMemory() (MemorySnapshot, error)
ReadMemory returns one memory and swap snapshot from Linux.
type NetworkInterface ¶
type NetworkInterface struct {
Name string
Index uint32
ReceiveBytes uint64
ReceivePackets uint64
ReceiveErrors uint64
ReceiveDropped uint64
TransmitBytes uint64
TransmitPackets uint64
TransmitErrors uint64
TransmitDropped uint64
Rates NetworkRates
}
NetworkInterface contains cumulative counters and derived rates for one interface.
type NetworkRates ¶
type NetworkRates struct {
ReceiveBytesPerSecond float64
TransmitBytesPerSecond float64
ReceivePacketsPerSecond float64
TransmitPacketsPerSecond float64
Valid bool
}
NetworkRates contains rates derived from two network observations. Valid distinguishes observed zero rates from unavailable derived values.
type NetworkSampler ¶
type NetworkSampler struct {
// contains filtered or unexported fields
}
NetworkSampler retains previous interface counters for sequential rate sampling.
func NewNetworkSampler ¶
func NewNetworkSampler() *NetworkSampler
NewNetworkSampler returns a network sampler owned by one sequential polling caller.
func (*NetworkSampler) Sample ¶
func (s *NetworkSampler) Sample() (NetworkSnapshot, error)
Sample returns one network-interface snapshot. The sampler is not safe for concurrent use.
type NetworkSnapshot ¶
type NetworkSnapshot struct {
CollectedAt time.Time
Interfaces []NetworkInterface
Issues []Issue
}
NetworkSnapshot contains network-interface data collected at one time. Interfaces and Issues are caller-owned snapshot slices.
type Process ¶ added in v0.4.0
type Process struct {
Identity ProcessIdentity
Name string
ParentPID int
UID uint32
UIDValid bool
ResidentBytes uint64
ResidentValid bool
Args []string
CPU CPUUsage
}
Process contains one process observation and its best-effort derived CPU usage.
type ProcessIdentity ¶ added in v0.4.0
ProcessIdentity distinguishes a process from a later process that reuses its PID.
type ProcessSampler ¶ added in v0.4.0
type ProcessSampler struct {
// contains filtered or unexported fields
}
ProcessSampler retains previous process and aggregate CPU counters for sequential rate sampling. previousTotal is the aggregate tick count read before the previous process walk. The next sample closes that window with a second read taken after its own walk, so both process stats fall inside it.
func NewProcessSampler ¶ added in v0.4.0
func NewProcessSampler() *ProcessSampler
NewProcessSampler returns a process sampler owned by one sequential polling caller.
func (*ProcessSampler) Sample ¶ added in v0.4.0
func (s *ProcessSampler) Sample() (ProcessSnapshot, error)
Sample returns one process snapshot. The sampler is not safe for concurrent use.
Aggregate ticks are read before the walk and again after every process stat. The window for this sample runs from the previous pre-walk read to this post-walk read, which covers both process observations. A saturated process read later than the opening /proc/stat therefore stays inside the fraction instead of being dropped (issue #21). A delta that still exceeds that covering window is a counter regression and stays invalid (issue #7).
type ProcessSnapshot ¶ added in v0.4.0
ProcessSnapshot contains processes collected at one time. Processes, Args, and Issues are caller-owned snapshot slices.
type ThermalSnapshot ¶ added in v0.3.0
type ThermalSnapshot struct {
CollectedAt time.Time
Celsius float64
Valid bool
Source string
Issues []Issue
}
ThermalSnapshot is one scored CPU package temperature in Celsius. Valid is false when no known sensor exists; that is not an error.
func ReadThermal ¶ added in v0.3.0
func ReadThermal() (ThermalSnapshot, error)
ReadThermal collects the current CPU package temperature.
type UptimeSnapshot ¶
UptimeSnapshot contains uptime as a duration collected at one time.
func ReadUptime ¶
func ReadUptime() (UptimeSnapshot, error)
ReadUptime returns one uptime snapshot from Linux.
