prometheus

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 8 Imported by: 0

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 New

func New() *Registry

New creates a new Registry ready for use as a metrics.Backend.

func (*Registry) Handler

func (r *Registry) Handler() http.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

func (r *Registry) IncCounter(name string, delta uint64)

IncCounter implements metrics.Backend. It increments the named counter by delta. The name is sanitized before storage.

func (*Registry) ObserveLatency

func (r *Registry) ObserveLatency(name string, d time.Duration)

ObserveLatency implements metrics.Backend. It records d in the latency histogram named name. The name is sanitized before storage.

func (*Registry) WriteText

func (r *Registry) WriteText(w io.Writer)

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.

Jump to

Keyboard shortcuts

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