metrics

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package metrics provides a lightweight in-process metrics registry with Prometheus text-format output. It requires zero external dependencies.

Instrumented points on the hot path:

  • agentguard_checks_total — counter, by decision label
  • agentguard_request_duration_ms — histogram, end-to-end /v1/check
  • agentguard_policy_eval_duration_ms — histogram, Engine.Check only
  • agentguard_audit_write_duration_ms — histogram, Logger.Log only
  • agentguard_pending_approvals — gauge, current queue depth

Index

Constants

This section is empty.

Variables

View Source
var (
	ChecksTotal      uint64 // all /v1/check requests
	AllowedTotal     uint64
	DeniedTotal      uint64
	ApprovalTotal    uint64 // REQUIRE_APPROVAL decisions
	RateLimitedTotal uint64 // rate-limit denies
)
View Source
var (
	RequestDuration    = newHistogram(durationBuckets)
	PolicyEvalDuration = newHistogram(durationBuckets)
	AuditWriteDuration = newHistogram(durationBuckets)
)

Package-level histograms.

Functions

func IncDecision

func IncDecision(decision string)

IncDecision increments the appropriate decision counter.

func IncRateLimited

func IncRateLimited()

IncRateLimited increments the rate-limit deny counter.

func SetPendingApprovals

func SetPendingApprovals(n int)

SetPendingApprovals sets the current queue depth gauge.

func WritePrometheus

func WritePrometheus(w io.Writer)

WritePrometheus writes all metrics to w in the Prometheus text exposition format (https://prometheus.io/docs/instrumenting/exposition_formats/).

Types

type Histogram

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

Histogram tracks a distribution using cumulative bucket counts. Each bucket counts observations with value ≤ the bucket bound, which is the Prometheus histogram convention.

func (*Histogram) Observe

func (h *Histogram) Observe(ms float64)

Observe records one observation in milliseconds.

func (*Histogram) Snapshot

func (h *Histogram) Snapshot() (buckets []float64, counts []uint64, sum float64, total uint64)

Snapshot returns a copy of internal state under the lock.

Jump to

Keyboard shortcuts

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