Help us shape the future of Go! Take the 2026 Go Developer Survey

metrics

package
v0.1.38 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package metrics provides a UI-independent background collector that samples the active cluster's message counts and broker stats on an interval, derives message-in rates from the count deltas between cycles, and caches the results plus a rolling time-series history so the metrics page can read them without blocking. It mirrors the design of pkg/cluster/collector.go.

Collection is driven purely through the api.KafkaDataSource interface (GetTopics, GetTopicMessageCounts, GetBrokerStats), which operate on the active context — so the collector samples whichever cluster is currently selected. Byte rates require a configured metrics endpoint; that path is a documented stub and byte rates are otherwise api.RateUnknown.

Index

Constants

View Source
const ExpositionContentType = "text/plain; version=0.0.4; charset=utf-8"

ExpositionContentType is the Prometheus text exposition format content type.

Variables

This section is empty.

Functions

func NewExpositionHandler

func NewExpositionHandler(src SnapshotLister, enabledFor func(cluster string) bool) http.Handler

NewExpositionHandler builds the flag-gated Prometheus exposition handler (MM-16). enabledFor reports whether a cluster opts in to exposition; clusters for which it returns false are 404 on their own path and excluded from the merged global endpoint.

  • GET /metrics merged families across all opted-in clusters
  • GET /metrics/{cluster} a single cluster (404 unknown or opted-out)

Types

type CollectTickMsg

type CollectTickMsg struct{}

CollectTickMsg triggers a periodic collection; the subscriber turns it into a CollectCmd (see pkg/ui wiring), mirroring the cluster collector.

type Collector

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

Collector samples the active cluster and caches metrics + history. Safe for concurrent use: the background loop writes while the UI reads.

func New

func New(ds api.KafkaDataSource, interval time.Duration, endpointFor func(string) string) *Collector

New builds a Collector. interval <= 0 falls back to the config default. endpointFor may be nil (no metrics endpoints configured anywhere).

func (*Collector) Active

func (c *Collector) Active() (api.ClusterMetrics, bool)

Active returns the cached metrics for the currently-selected cluster.

func (*Collector) ActiveMessagesInHistory

func (c *Collector) ActiveMessagesInHistory() api.TimeSeries

ActiveMessagesInHistory returns the message-in-rate series for the active cluster.

func (*Collector) CollectAll

func (c *Collector) CollectAll(ctx context.Context)

CollectAll runs one collection cycle against the active cluster and updates the cache atomically. Fetch failures leave the previous snapshot in place.

func (*Collector) CollectCmd

func (c *Collector) CollectCmd() tea.Cmd

CollectCmd runs a full collection cycle and reports the refreshed active snapshot. While a cycle is already running it does nothing and reports nothing: the running cycle's MetricsUpdatedMsg serves both callers, and one slow cycle can never stack another on top of it against the same brokers.

func (*Collector) Interval

func (c *Collector) Interval() time.Duration

Interval returns the configured collection cadence.

func (*Collector) List

func (c *Collector) List() []api.ClusterMetrics

List returns cached metrics for all seen clusters in stable order.

func (*Collector) MessagesInHistory

func (c *Collector) MessagesInHistory(cluster string) api.TimeSeries

MessagesInHistory returns the retained message-in-rate series for a cluster.

func (*Collector) SetSettingsResolver

func (c *Collector) SetSettingsResolver(fn func(cluster string) appconfig.MetricsSettings)

SetSettingsResolver installs a resolver for per-cluster metrics settings so the collector can honor Type "JMX" via the Jolokia bridge (MM-17). It is wired from the UI boot path; without it collection stays Prometheus-only.

func (*Collector) Snapshot

func (c *Collector) Snapshot(cluster string) (api.ClusterMetrics, bool)

Snapshot returns the cached metrics for a cluster. ok is false for an unknown cluster.

func (*Collector) TickCmd

func (c *Collector) TickCmd() tea.Cmd

TickCmd schedules the next collection cycle after the configured interval. Callers arm it once a cycle has reported back, not alongside the cycle, so the interval is the pause between cycles rather than their start rate.

type MetricsUpdatedMsg

type MetricsUpdatedMsg struct {
	Active api.ClusterMetrics
}

MetricsUpdatedMsg is emitted after a collection cycle so the metrics page can re-render from the collector cache without polling.

type SnapshotLister

type SnapshotLister interface {
	List() []api.ClusterMetrics
}

SnapshotLister provides the cached per-cluster snapshots the exposition endpoint renders. *Collector satisfies it.

Directories

Path Synopsis
Package graphs is a built-in catalog of Prometheus graph descriptions and the logic that renders their query templates and executes them against the optional time-series backend (pkg/metrics/promquery).
Package graphs is a built-in catalog of Prometheus graph descriptions and the logic that renders their query templates and executes them against the optional time-series backend (pkg/metrics/promquery).
Package jolokia is an HTTP-bridge collector for JMX metrics exposed through a Jolokia agent.
Package jolokia is an HTTP-bridge collector for JMX metrics exposed through a Jolokia agent.
Package promquery is a minimal client for the Prometheus HTTP query API (/api/v1/query and /api/v1/query_range) built on the standard library only.
Package promquery is a minimal client for the Prometheus HTTP query API (/api/v1/query and /api/v1/query_range) built on the standard library only.

Jump to

Keyboard shortcuts

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