metrics

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 2 Imported by: ? 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

Overview

Package metrics provides lightweight metric collection primitives.

It contains self-contained, dependency-free metric types (currently LatencyHistogram) that the engine uses to record operation latencies. The values are exposed to scrapers by the route layer's Prometheus text-format handler; no third-party Prometheus client library is pulled in, keeping the core industrial gateway dependency-light.

Index

Constants

This section is empty.

Variables

View Source
var DefaultDataAgeBuckets = []float64{0.1, 0.5, 1, 5, 10, 30, 60, 300, 600}

DefaultDataAgeBuckets are the histogram bucket upper bounds (in seconds) used for data age (freshness): the elapsed time between a data point's collection timestamp (DataPoint.Timestamp) and the moment the engine attempts to publish it. The scale is larger than I/O latency buckets because data age includes scheduler queuing, batching, and — during transport outages — offline-buffer replay, so values can reach minutes.

View Source
var DefaultPublishLatencyBuckets = []float64{0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10}

DefaultPublishLatencyBuckets are the histogram bucket upper bounds (in seconds) used for transport publish latency. It uses the same scale as read latency since both are short-lived network I/O operations.

View Source
var DefaultReadLatencyBuckets = []float64{0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10}

DefaultReadLatencyBuckets are the histogram bucket upper bounds (in seconds) used for driver read latency. The scale covers sub-millisecond field-bus reads through multi-second reads typical of PLC/OPC-UA I/O over slow or congested links.

Functions

This section is empty.

Types

type LatencyHistogram

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

LatencyHistogram is a lightweight, mutex-guarded histogram for tracking operation latencies without a full metrics client dependency.

It follows the Prometheus cumulative-bucket convention: each entry in counts is the number of observations whose duration is less than or equal to the corresponding entry in buckets (i.e. counts are cumulative). An implicit +Inf bucket equal to count is assumed when rendering; observations that exceed every configured bucket increment only count and sum, not any counts entry.

All methods are safe for concurrent use.

func NewLatencyHistogram

func NewLatencyHistogram(buckets []float64) *LatencyHistogram

NewLatencyHistogram creates a LatencyHistogram with the given bucket upper bounds (in seconds). The buckets slice is copied so later mutation of the caller's slice does not affect the histogram. Callers should pass a strictly increasing, ascending-sorted slice (e.g. DefaultReadLatencyBuckets); a nil or empty slice yields a histogram that records only the sum and count.

func (*LatencyHistogram) Observe

func (h *LatencyHistogram) Observe(d time.Duration)

Observe records a single observation of duration d. It increments every cumulative bucket whose upper bound is greater than or equal to d (maintaining the Prometheus cumulative invariant), adds d to the running sum, and increments the total observation count. Observations that exceed all configured buckets still update sum and count.

func (*LatencyHistogram) Snapshot

func (h *LatencyHistogram) Snapshot() (buckets []float64, counts []uint64, sum float64, count uint64)

Snapshot returns a thread-safe copy of the histogram's current state. The returned slices are independent copies and may be mutated freely by the caller. buckets is the list of upper bounds (in seconds), counts is the aligned list of cumulative per-bucket counts, sum is the total observed duration in seconds, and count is the total number of observations.

Jump to

Keyboard shortcuts

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