host

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 24 Imported by: 1 module, 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 host collects host and process metrics with OTel semantic-convention names, through gopsutil (pure Go, no cgo, Linux/Windows/macOS).

Index

Constants

View Source
const (
	EmitOTel         = "otel"          // semconv names only (default)
	EmitNodeExporter = "node_exporter" // node_* names only
	EmitBoth         = "both"
)

Emit modes for Config.Emit.

View Source
const (
	KindFilesystem = "filesystem"
	KindDisk       = "disk"
	KindNIC        = "nic"
	KindGPU        = "gpu"
)

Kinds that low-level discovery can enumerate.

View Source
const MaxProcesses = 50

MaxProcesses caps each process list (top by CPU, top by memory). Live agent-served process views are known gap G-24; this is sampled metrics only.

Variables

This section is empty.

Functions

func Collect

func Collect(out sink.Sink, d Discovery, at time.Time)

Collect takes one pass of host metrics. A failing source is logged and skipped.

func CollectDepth

func CollectDepth(out sink.Sink, at time.Time)

CollectDepth adds the node_exporter-depth series: per-core and per-mode CPU time, paging and swap, process counts, context switches and TCP connection states.

func CollectKernel

func CollectKernel(out sink.Sink, root string, at time.Time)

CollectKernel emits the kernel inputs on Linux; elsewhere it does nothing.

func Duration

func Duration(s string, def, floor time.Duration) time.Duration

Duration parses s, falling back to def and clamping up to floor.

func EmitCPUTimes

func EmitCPUTimes(out sink.Sink, ts []cpu.TimesStat, at time.Time)

EmitCPUTimes writes system.cpu.time per logical CPU and mode (cumulative seconds).

func EmitDiskDepth

func EmitDiskDepth(out sink.Sink, d Discovery, stats map[string]disk.IOCountersStat, at time.Time)

EmitDiskDepth writes operation counts, operation time, busy time and queue depth per disk.

func EmitFilesystems

func EmitFilesystems(out sink.Sink, d Discovery, fss []FS, at time.Time)

EmitFilesystems writes system.filesystem.usage for each filesystem the discovery rules allow. The parent host is not stamped: the worker derives it from the resource host.name.

func EmitHwmon

func EmitHwmon(out sink.Sink, dir string, at time.Time)

EmitHwmon writes hw.temperature (degrees Celsius) for every hwmon temp*_input sensor.

func EmitIO

func EmitIO(out sink.Sink, d Discovery, kind, name string, devs map[string][2]uint64, dirs [2]string, at time.Time)

EmitIO writes a cumulative byte counter per device and direction (dirs[0] for vals[0]).

func EmitMeminfoDepth

func EmitMeminfoDepth(out sink.Sink, r io.Reader, at time.Time)

EmitMeminfoDepth writes huge pages and slab memory from /proc/meminfo.

func EmitNICDepth

func EmitNICDepth(out sink.Sink, d Discovery, nics []gnet.IOCountersStat, at time.Time)

EmitNICDepth writes packets, errors and drops per interface and direction.

func EmitProcStat

func EmitProcStat(out sink.Sink, r io.Reader, at time.Time)

EmitProcStat writes the interrupt total (`intr`), soft interrupts and boot time from /proc/stat.

func EmitProcesses

func EmitProcesses(out sink.Sink, samples []ProcSample, prev map[int32]float64, elapsed time.Duration, at time.Time) map[int32]float64

EmitProcesses writes process.cpu.utilization for the top processes by CPU (a fraction of all cores, from the change since prev over elapsed) and process.memory.usage for the top by memory. It returns the new cumulative CPU map.

func EmitSelected

func EmitSelected(out sink.Sink, samples []ProcSample, globs []string, at time.Time)

EmitSelected writes process.cpu.time and process.memory.usage for every process whose executable name matches one of the globs (Telegraf procstat selection), top-N or not.

func Every

func Every(ctx context.Context, interval time.Duration, fn func(ctx context.Context))

Every calls fn now and then every interval until ctx ends.

func ParseProcNetTCP

func ParseProcNetTCP(r io.Reader, counts map[string]int)

ParseProcNetTCP adds the sockets of one /proc/net/tcp-format table to counts by state name.

func ParseSNMP

func ParseSNMP(r io.Reader) map[string]float64

ParseSNMP reads /proc/net/snmp (a header line and a value line per protocol) into nstat names.

func Redact

func Redact(err error, secrets ...string) error

Redact returns err with every non-empty secret replaced, so a credential a library echoes in an error never reaches a log, a label or the wire.

func Run

func Run(ctx context.Context, raw json.RawMessage, out sink.Sink) error

Run collects until ctx ends. A disabled module just waits.

func Warn

func Warn(key string, err error)

Warn logs err for key at most once per 10 minutes, so a persistent failure (bad credentials, unreachable target) is visible without flooding the log. err must already be redacted.

func WrapEmit

func WrapEmit(out sink.Sink, mode string) sink.Sink

WrapEmit returns out wrapped for the emit mode; an unknown or otel mode returns out itself.

Types

type Config

type Config struct {
	Enabled         *bool     `json:"enabled"`
	Interval        string    `json:"interval"`         // default 10s, at least 1s
	ProcessInterval string    `json:"process_interval"` // default 30s, at least 5s
	Processes       *bool     `json:"processes"`        // default true
	ProcessNames    []string  `json:"process_names"`    // globs of executable names always reported (procstat)
	Discovery       Discovery `json:"discovery"`
	Emit            string    `json:"emit"` // otel (default), node_exporter or both
}

Config is the host module's config. Only Enabled and Interval can be set remotely.

func ParseConfig

func ParseConfig(raw json.RawMessage) (Config, error)

ParseConfig decodes and validates cfg (empty means defaults).

type Discovery

type Discovery []Rule

Discovery is the list of rules. A kind without a rule is collected whole.

func (Discovery) Allow

func (d Discovery) Allow(kind, name string) bool

Allow reports whether the child called name of kind is collected.

func (Discovery) Children

func (d Discovery) Children(kind string, names []string) []string

Children returns the names of kind that the rules let through, in order.

func (Discovery) Validate

func (d Discovery) Validate() error

Validate checks kinds and patterns.

type FS

type FS struct {
	Device, Mount, Type string
	Used, Free          uint64
	// InodesUsed and InodesFree are 0 on filesystems without inodes (FAT, NTFS via gopsutil).
	InodesUsed, InodesFree uint64
}

FS is one mounted filesystem.

type NodeAliasSink

type NodeAliasSink struct {
	Inner     sink.Sink
	OnlyAlias bool
}

NodeAliasSink forwards to Inner and also (or only, when OnlyAlias) writes the node_exporter name for each sample that has one. A sample with no alias is always forwarded.

func (NodeAliasSink) Gauge

func (n NodeAliasSink) Gauge(name, unit string, v float64, attrs map[string]string, at time.Time)

Gauge implements sink.Sink.

func (NodeAliasSink) Log

func (n NodeAliasSink) Log(sev, body string, attrs map[string]string, at time.Time)

Log implements sink.Sink.

func (NodeAliasSink) Sum

func (n NodeAliasSink) Sum(name, unit string, v float64, attrs map[string]string, at time.Time)

Sum implements sink.Sink.

type Object

type Object struct {
	Kind, Name string
	Labels     map[string]string
}

Object is one discovered child of the host, with the labels its metrics carry.

func Objects

func Objects(d Discovery) []Object

Objects lists the filesystems, disks and interfaces the discovery rules let through: the same children Collect reports, for low-level-discovery rule prototypes (rulesync/lld.go).

type ProcSample

type ProcSample struct {
	PID     int32
	Name    string
	CPUSecs float64 // cumulative user+system seconds
	RSS     uint64
}

ProcSample is one process at one sample.

func TopN

func TopN(in []ProcSample, key func(ProcSample) float64) []ProcSample

TopN returns at most MaxProcesses samples with the largest key, largest first. Ties break by pid so the result is stable.

type Processes

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

Processes samples the process table on its own, slower, schedule.

func NewProcesses

func NewProcesses(every time.Duration) *Processes

NewProcesses returns a sampler that runs at most once per every.

func (*Processes) Maybe

func (p *Processes) Maybe(out sink.Sink, now time.Time)

Maybe samples when due. It is safe on a nil receiver (processes disabled).

type Rule

type Rule struct {
	Kind    string   `json:"kind"`
	Include []string `json:"include"`
	Exclude []string `json:"exclude"`
}

Rule is one low-level discovery rule (INF-020). Include and Exclude are path.Match globs against the child's name (mount point, device, interface or GPU index). No include means all; exclude wins.

Jump to

Keyboard shortcuts

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