Documentation
¶
Overview ¶
Package prometheus provides a [metrics.Backend] implementation that produces Prometheus-compatible text exposition output — with no dependency on github.com/prometheus/client_golang. The native Prometheus text format (version 0.0.4) is serialised directly, keeping the entire metrics sub-system import-graph clean.
Wire-up ¶
Install the backend early in main before any blocking APIs are called:
import (
"github.com/FlavioCFOliveira/GoGraph/internal/metrics"
"github.com/FlavioCFOliveira/GoGraph/internal/metrics/prometheus"
)
reg := prometheus.New()
metrics.SetBackend(reg)
// Expose over HTTP:
http.Handle("/metrics", reg.Handler())
Concurrency ¶
Registry is safe for concurrent use. Counter increments and histogram observations are lock-free once the named series has been created; the write-lock is held only during the first creation of a new name.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a metrics.Backend that formats observations as Prometheus text exposition (version 0.0.4). It requires no external dependencies.
All methods are safe for concurrent use. Counter and histogram lookups are lock-free after the first observation for a given name.
func (*Registry) Handler ¶
Handler returns an http.Handler that serves all collected metrics in Prometheus text exposition format on every GET request. The response carries Content-Type: text/plain; version=0.0.4; charset=utf-8.
func (*Registry) IncCounter ¶
IncCounter implements metrics.Backend. It increments the named counter by delta. The name is sanitized before storage.
func (*Registry) ObserveLatency ¶
ObserveLatency implements metrics.Backend. It records d in the latency histogram named name. The name is sanitized before storage.
func (*Registry) WriteText ¶
WriteText writes all collected metrics to w in Prometheus text exposition format (version 0.0.4).
Metrics are emitted in two groups — counters first, then histograms — each sorted alphabetically by name so the output is deterministic. The first write error, if any, is returned; partial output may have been written before the error occurred.