Documentation
¶
Overview ¶
Package psutil provides a debug endpoint that returns host/process system statistics.
This package integrates github.com/shirou/gopsutil to collect a point-in-time snapshot of basic system metrics such as CPU, host info, load averages, memory/swap stats, and network I/O counters.
The endpoint is typically registered on the debug HTTP mux under:
/debug/psutil
(namespaced by service name via debug/http.Pattern).
Notes:
- Collection is best-effort: errors returned by gopsutil calls are intentionally ignored and the corresponding fields may be partially populated or empty.
- The endpoint is intended for diagnostics and operations; consider access control and exposure carefully in production environments.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
func NewHandler(cont *content.Content) http.HandlerFunc
NewHandler constructs the HTTP handler that returns a psutil snapshot response.
The handler collects a point-in-time view of system information using gopsutil-backed helpers in this package (CPU, host info, load averages, memory/swap, and network counters).
Collection is best-effort: underlying collection helpers intentionally ignore gopsutil errors, so individual sections may be partially populated or empty depending on platform support and runtime permissions.
The handler is typically registered under /debug/psutil (namespaced by service name via debug/http.Pattern).
Types ¶
type CPU ¶
type CPU struct {
// Info contains static CPU information (model, cores, cache sizes, etc.).
Info []cpu.InfoStat `yaml:"info,omitempty" json:"info,omitempty" toml:"info,omitempty"`
// Times contains per-CPU time statistics (user/system/idle/etc.).
Times []cpu.TimesStat `yaml:"times,omitempty" json:"times,omitempty" toml:"times,omitempty"`
}
CPU contains CPU details collected for the debug endpoint.
type Host ¶
type Host struct {
// Info contains host information (OS, platform, uptime, etc.).
Info *host.InfoStat `yaml:"info,omitempty" json:"info,omitempty" toml:"info,omitempty"`
}
Host contains host/system details collected for the debug endpoint.
type Load ¶
type Load struct {
// Avg contains load averages (for example 1m/5m/15m).
Avg *load.AvgStat `yaml:"avg,omitempty" json:"avg,omitempty" toml:"avg,omitempty"`
}
Load contains system load details collected for the debug endpoint.
type Mem ¶
type Mem struct {
// Swap contains overall swap memory statistics.
Swap *mem.SwapMemoryStat `yaml:"swap,omitempty" json:"swap,omitempty" toml:"swap,omitempty"`
// Virtual contains virtual memory statistics.
Virtual *mem.VirtualMemoryStat `yaml:"virtual,omitempty" json:"virtual,omitempty" toml:"virtual,omitempty"`
// Devices contains per-device swap usage information.
Devices []*mem.SwapDevice `yaml:"devices,omitempty" json:"devices,omitempty" toml:"devices,omitempty"`
}
Mem contains memory details collected for the debug endpoint.
type Net ¶
type Net struct {
// Counters contains per-interface network I/O counters.
Counters []net.IOCountersStat `yaml:"counters,omitempty" json:"counters,omitempty" toml:"counters,omitempty"`
}
Net contains network details collected for the debug endpoint.
type Response ¶
type Response struct {
// CPU contains CPU information and time statistics.
CPU *CPU `yaml:"cpu,omitempty" json:"cpu,omitempty" toml:"cpu,omitempty"`
// Host contains host/system information (OS, platform, uptime, etc.).
Host *Host `yaml:"host,omitempty" json:"host,omitempty" toml:"host,omitempty"`
// Load contains system load averages (where supported by the OS).
Load *Load `yaml:"load,omitempty" json:"load,omitempty" toml:"load,omitempty"`
// Mem contains memory and swap statistics.
Mem *Mem `yaml:"mem,omitempty" json:"mem,omitempty" toml:"mem,omitempty"`
// Net contains network I/O counters.
Net *Net `yaml:"net,omitempty" json:"net,omitempty" toml:"net,omitempty"`
}
Response is the response body returned by the psutil debug endpoint.
All fields are optional and may be nil if collection failed or if the platform does not support the underlying metric. Fields are tagged for common config/encoding formats (YAML/JSON/TOML) to support standard response encoders used in go-service.