metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package metrics provides system and LLM usage metrics for tmux-webui.

Overview

The package defines a Provider interface and a Snapshot value type. Two concrete providers are available:

  • StubProvider: always returns an empty Snapshot; used by default in v0 to avoid introducing a gopsutil dependency before it is needed.

  • HTTPProvider: fetches a JSON payload from a configurable URL (e.g. http://127.0.0.1:10103/sysmon/current from the agent-metrics station) and maps the display fields onto Snapshot. Parsing logic mirrors the Python status_metrics() function in tmux_manager.py.

Configuration

// from config.MetricsConfig
if cfg.Metrics.Provider == "http" && cfg.Metrics.URL != "" {
    prov = metrics.NewHTTP(cfg.Metrics.URL)
} else {
    prov = metrics.NewStub()
}

LLM key convention

The sysmon JSON can contain keys of the form llm_{provider}_{metric} (e.g. llm_cc_5h, llm_gm_pro). HTTPProvider groups these into a nested map[provider]map[metric]value, dropping empty / "?" values. The key llm_display is explicitly excluded.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider interface {
	Collect(ctx context.Context) Snapshot
}

Provider collects a Snapshot on demand. Implementations must be safe for concurrent use and must never block indefinitely — callers hold locks or are inside a ticker goroutine.

func NewHTTP

func NewHTTP(url string) Provider

NewHTTP returns a Provider that fetches metrics from the given URL. url should be the sysmon/current endpoint, e.g. "http://127.0.0.1:10103/sysmon/current".

func NewStub

func NewStub() Provider

NewStub returns a Provider that always returns an empty Snapshot. Use this as the default until a real provider is configured.

type Snapshot

type Snapshot struct {
	Net  string                       `json:"net,omitempty"`
	CPU  string                       `json:"cpu,omitempty"`
	Mem  string                       `json:"mem,omitempty"`
	Disk string                       `json:"disk,omitempty"`
	LLM  map[string]map[string]string `json:"llm,omitempty"`
}

Snapshot holds a point-in-time view of system and LLM usage metrics. All string fields use the pre-formatted display strings produced by the agent-metrics sysmon endpoint — ready to render in the UI as-is.

Fields are omitted from JSON when empty so the WebSocket payload stays lean.

Jump to

Keyboard shortcuts

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