pmetrics

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package pmetrics is a tool's Prometheus metrics page: its own readings and nothing else, with the labels whoever runs it wants on every one, written as text or served over HTTP beside a health probe.

Index

Constants

View Source
const (
	// Path is where the page is served.
	Path = "/metrics"
	// HealthPath answers "ok" while the tool is serving, whatever state the thing it reports on is in: a container is not unhealthy because what it
	// watches is down.
	HealthPath = "/healthz"
)

Variables

This section is empty.

Functions

func ParseLabels

func ParseLabels(s string) (map[string]string, error)

ParseLabels reads labels from a setting written name=value,name=value, as LEONTP_METRICS_LABELS=hostname=ntp,site=home is; spaces around a name or a value are dropped, and nothing at all is no labels. A value cannot hold a comma.

func Serve

func Serve(ctx context.Context, listen string, h http.Handler) error

Serve serves h on listen until the context ends, then lets requests under way finish. Whoever calls it ends the context on a signal.

func ValidateLabels

func ValidateLabels(labels map[string]string) error

ValidateLabels says what is wrong with the first label, by name, that a metrics store would not take: a name that is not letters, digits and underscores, one that starts with a digit or with the two underscores a store keeps for itself, or a label with no value.

Types

type Options

type Options struct {
	// Name is the tool's name, "leontp-metrics": what the root of the server answers with, beside its version.
	Name string
	// Namespace starts the name of the one reading the page adds itself, which says what build wrote it: "leontp" gives leontp_metrics_build_info.
	Namespace string
	// Labels are put on every reading on the page: hostname=ntp say, for a store that tells one source from another by them. ParseLabels reads
	// them from a setting.
	Labels map[string]string
}

Options says what the page is.

type Page

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

Page holds a tool's readings and writes them out. It holds none of the Go runtime's or the process's own.

func New

func New(o Options, collectors ...prometheus.Collector) (*Page, error)

New is the page of these collectors' readings, each with the labels on it, and one more that says which build wrote the page. A label under a name a reading already has is an error, as is one a metrics store would not take: said when the tool starts, not found missing on a dashboard.

func (*Page) Handler

func (p *Page) Handler() http.Handler

Handler is the routes: the page at Path, the health probe at HealthPath, and at the root a few lines saying where they are. Apart from Serve so they can be tested or mounted elsewhere without a port.

func (*Page) Write

func (p *Page) Write(w io.Writer) error

Write writes the page as text, the way a scrape reads it.

Jump to

Keyboard shortcuts

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