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 ¶
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 ¶
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 ¶
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 ¶
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.