collector

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 18 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

Rendered for windows/amd64

Index

Constants

View Source
const (
	EventSnapshot     = "metrics.snapshot"
	EventProcessTree  = "metrics.process_tree"
	EventPortBindings = "metrics.port_bindings"
)

Event names emitted by the Manager via its Emitter.

Variables

This section is empty.

Functions

func BuildProcessTree

func BuildProcessTree(procs []metrics.ProcessInfo) []*metrics.ProcessNode

BuildProcessTree assembles a forest of ProcessNode roots from a flat list. Children are sorted by CPU descending. Processes whose parent does not exist (or whose parent's create time is later than the child's) are surfaced as orphan roots.

func CPUInfoFromRegistry

func CPUInfoFromRegistry() (string, uint32)

CPUInfoFromRegistry reads the processor name and base MHz from registry.

Types

type CPUCollector

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

CPUCollector samples system-wide CPU usage from GetSystemTimes plus per-core usage from NtQuerySystemInformation. Percentages are computed from deltas against the previous sample.

func NewCPUCollector

func NewCPUCollector(name string, freqMHz uint32) *CPUCollector

NewCPUCollector creates a CPU collector. cpuName/freqMHz come from the registry collector at startup; the collector will fall back to defaults if either is empty.

func (*CPUCollector) Collect

func (c *CPUCollector) Collect() metrics.CPUMetrics

Collect returns a populated CPUMetrics. The first call returns zeros for percent (no delta yet) but populates static fields.

type DiskCollector

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

DiskCollector returns the list of visible drives plus live LogicalDisk I/O counters.

func NewDiskCollector

func NewDiskCollector() *DiskCollector

func (*DiskCollector) Collect

func (d *DiskCollector) Collect() metrics.DiskMetrics

type GPUCollector

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

GPUCollector returns live engine utilization and adapter memory usage via built-in Windows perf counters, with adapter metadata sourced from registry.

func NewGPUCollector

func NewGPUCollector() *GPUCollector

func (*GPUCollector) Collect

func (g *GPUCollector) Collect() metrics.GPUMetrics

type Manager

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

Manager owns every collector, the latest snapshot, and the storage. It runs three independent ticker loops:

  • Fast: CPU/memory/network/disk + processes (config.Monitoring.Interval)
  • ProcessTree: builds a tree from the latest processes
  • Ports: enumerates TCP/UDP endpoints

func NewManager

func NewManager(cfg *config.Config, store *storage.Store, emitter *event.Emitter, cpuName string, cpuMHz uint32) *Manager

NewManager wires every collector together. cpuName/freqMHz are sourced from the registry by the caller (cmd/wtm) before calling here.

func (*Manager) ApplyConfig

func (m *Manager) ApplyConfig(cfg *config.Config)

ApplyConfig updates collectors that have config-derived state.

func (*Manager) CollectOnce

func (m *Manager) CollectOnce() *metrics.SystemSnapshot

CollectOnce runs the fast collectors synchronously and returns the snapshot. Used at startup so the first HTTP request sees data.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context)

Start launches all background sample loops. It returns immediately; loops exit when ctx is cancelled.

type MemoryCollector

type MemoryCollector struct{}

MemoryCollector samples physical and virtual memory state.

func NewMemoryCollector

func NewMemoryCollector() *MemoryCollector

func (*MemoryCollector) Collect

func (m *MemoryCollector) Collect() metrics.MemoryMetrics

type NetworkCollector

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

NetworkCollector samples per-interface throughput.

func NewNetworkCollector

func NewNetworkCollector() *NetworkCollector

func (*NetworkCollector) Collect

type PortCollector

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

PortCollector enumerates TCP/UDP endpoints and tracks how long each (proto, local, remote, state) tuple has existed for port-conflict anomaly detection.

func NewPortCollector

func NewPortCollector(wellKnown map[uint16]string) *PortCollector

func (*PortCollector) Collect

func (pc *PortCollector) Collect(resolveName func(pid uint32) string) []metrics.PortBinding

Collect returns the current port table. resolveName looks up a process name from PID — pass a closure backed by the latest process snapshot.

func (*PortCollector) SetWellKnown

func (pc *PortCollector) SetWellKnown(m map[uint16]string)

SetWellKnown replaces the well-known port label map (used after config reload).

type ProcessCollector

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

ProcessCollector enumerates running processes and computes per-process CPU%.

func NewProcessCollector

func NewProcessCollector(maxResults int) *ProcessCollector

func (*ProcessCollector) Collect

func (pc *ProcessCollector) Collect() []metrics.ProcessInfo

Collect returns the current process list. It limits results to maxResults after sorting by working set descending so we always retain the heaviest processes when there are too many.

Jump to

Keyboard shortcuts

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