metrics

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package metrics owns every Prometheus metric Jō-ei exposes.

Hook rule: no other package imports client_golang. They expose optional observer hooks (funcs or small interfaces) and cmd/jo-ei wires them to the methods here.

To add a metric:

  1. Add its collector as an unexported field on a sub-struct of Metrics and register it in New (or a helper New calls) on m.Registry.
  2. Expose a nil-safe Wrap*/Register*/Observe* method that updates it.
  3. Constrain every label value to a closed set via oneOf; use newDurationHistogramOpts for latency histograms.
  4. Touch it in newFullyWired (metrics_test.go) so lint and drift tests see it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpstreamHosts

func UpstreamHosts(upstreamLists ...[]string) []string

UpstreamHosts returns the deduplicated URL hosts (host[:port]) of every URL in upstreamLists, in first-seen order. Unparseable or host-less URLs are skipped. The result is the closed host-label set for upstream metrics.

Types

type BuildInfo

type BuildInfo struct{ Version, Commit string }

BuildInfo identifies the running binary.

type CacheStatter

type CacheStatter interface {
	Stats() (cache.CacheStats, error)
}

CacheStatter is the slice of the cache the size collector needs.

type Metrics

type Metrics struct {
	Registry *prometheus.Registry
	// contains filtered or unexported fields
}

Metrics holds the registry and all Jō-ei collectors.

A nil *Metrics is valid and means "metrics disabled": every Wrap*/Register* method added to this type is nil-safe and becomes a no-op or pass-through.

func New

func New(info BuildInfo, log zerolog.Logger) *Metrics

New builds a private registry with Go runtime, process and build-info collectors. It never touches prometheus.DefaultRegisterer.

func (*Metrics) Handler

func (m *Metrics) Handler() http.Handler

Handler serves the registry in Prometheus/OpenMetrics text format.

func (*Metrics) RegisterCache

func (m *Metrics) RegisterCache(s CacheStatter, maxBytes int64)

RegisterCache exposes jo_ei_cache_size_bytes (read at scrape time) and, when maxBytes > 0, the constant jo_ei_cache_max_bytes. Call it once per process: a repeated call is ignored. A nil *Metrics or nil s is a no-op.

func (*Metrics) RegisterCircuitBreaker

func (m *Metrics) RegisterCircuitBreaker(cb OpenHostsReporter, hosts []string)

RegisterCircuitBreaker exposes jo_ei_upstream_circuit_open, read from cb at scrape time, for each of hosts. Call it once per process: a repeated call is ignored (the first registration stays). A nil *Metrics is a no-op.

func (*Metrics) RegisterScannerHealth

func (m *Metrics) RegisterScannerHealth(snapshot func() []health.ScannerHealth, types map[string]string)

RegisterScannerHealth exposes jo_ei_scanner_up, derived from snapshot at scrape time. types maps a scanner's display name to its engine type (e.g. "kaspersky" → "icap") so operator-chosen names keep the label in the known set. Call it once per process: a repeated call is ignored. A nil *Metrics is a no-op.

func (*Metrics) ScanWaitObserver

func (m *Metrics) ScanWaitObserver() func(time.Duration)

ScanWaitObserver returns a func recording an AV scan's concurrency-slot wait into jo_ei_scan_queue_wait_seconds, or nil when m is nil (so callers skip timing entirely).

func (*Metrics) SetScanConcurrencyLimit

func (m *Metrics) SetScanConcurrencyLimit(n int)

SetScanConcurrencyLimit records the configured AV scan concurrency limit. A nil *Metrics is a no-op.

func (*Metrics) WrapAVScanner

func (m *Metrics) WrapAVScanner(engine string, s gate.AVScanner) gate.AVScanner

WrapAVScanner instruments s as the given engine (clamav, icap; anything else is "other"). A nil *Metrics returns s unchanged.

func (*Metrics) WrapCVEScanner

func (m *Metrics) WrapCVEScanner(engine string, s gate.CVEScanner) gate.CVEScanner

WrapCVEScanner instruments s as the given engine. A nil *Metrics returns s unchanged.

func (*Metrics) WrapHandler

func (m *Metrics) WrapHandler(next http.Handler, route RouteFunc) http.Handler

WrapHandler instruments next with request count, duration, in-flight and client-abort metrics. A nil *Metrics returns next unchanged.

func (*Metrics) WrapImageScanner

func (m *Metrics) WrapImageScanner(engine string, s dockerproxy.ImageScanner) dockerproxy.ImageScanner

WrapImageScanner instruments s as the given engine and forwards Health. A nil *Metrics returns s unchanged.

func (*Metrics) WrapRecorder

func (m *Metrics) WrapRecorder(r gate.Recorder) gate.Recorder

WrapRecorder counts every event in jo_ei_verdicts_total, then delegates to r. A nil *Metrics returns r unchanged.

func (*Metrics) WrapTransport

func (m *Metrics) WrapTransport(rt http.RoundTripper, hosts []string) http.RoundTripper

WrapTransport instruments rt with upstream request count, duration, in-flight and error-reason metrics. hosts is the closed host-label set (see UpstreamHosts); any other request host is labelled "other". Install it as the outermost layer of the upstream transport chain so rate-limit waits and circuit-open fast-fails are visible. It never registers collectors. A nil *Metrics returns rt unchanged.

type OpenHostsReporter

type OpenHostsReporter interface{ OpenHosts() []string }

OpenHostsReporter reports which upstream hosts currently have an open circuit. *httpx.CircuitBreaker implements it.

type RouteFunc

type RouteFunc func(path string) string

RouteFunc maps a request path to a bounded route label.

func NewRouteFunc

func NewRouteFunc(proxyPrefixes []string) RouteFunc

NewRouteFunc returns a RouteFunc that labels paths by first segment when it is one of proxyPrefixes ("v2" is reported as "docker"), and by fixed names for the console, API, health and favicon paths. Anything else is "other".

Jump to

Keyboard shortcuts

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