metrics

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package metrics collects Workly's metrics and serves them in the Prometheus text exposition format.

It implements the small subset of the format Workly needs (counters, gauges and histograms with labels) on the standard library, rather than pulling in a Prometheus client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter is a monotonically increasing value per label set.

func (*Counter) Add

func (c *Counter) Add(v float64, labelValues ...string)

func (*Counter) Inc

func (c *Counter) Inc(labelValues ...string)

type Gauge

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

Gauge is a value per label set that can go up and down.

func (*Gauge) Reset

func (g *Gauge) Reset()

Reset removes every label set, e.g. before refreshing per-queue gauges so deleted queues disappear.

func (*Gauge) Set

func (g *Gauge) Set(v float64, labelValues ...string)

type Histogram

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

Histogram counts observations into cumulative buckets per label set.

func (*Histogram) Observe

func (h *Histogram) Observe(v float64, labelValues ...string)

type Registry

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

Registry holds metric families and writes them in registration order.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Counter

func (r *Registry) Counter(name, help string, labels ...string) *Counter

func (*Registry) Gauge

func (r *Registry) Gauge(name, help string, labels ...string) *Gauge

func (*Registry) Handler

func (r *Registry) Handler() http.Handler

Handler serves the metrics.

func (*Registry) Histogram

func (r *Registry) Histogram(name, help string, buckets []float64, labels ...string) *Histogram

func (*Registry) OnCollect

func (r *Registry) OnCollect(fn func(ctx context.Context))

OnCollect registers a hook that runs before every scrape.

func (*Registry) Write

func (r *Registry) Write(ctx context.Context, w *bufio.Writer)

Write runs the collect hooks and writes every family.

type Workly

type Workly struct {
	*Registry

	// Counted by the replica that served the request.
	TasksEnqueued *Counter

	// Counted by the leader, which does all delivery.
	Attempts        *Counter
	TasksCompleted  *Counter
	AttemptDuration *Histogram
	DispatchLag     *Histogram
	IsLeader        *Gauge
	QueueAutoPauses *Counter

	// Read from the database at scrape time by the leader, so that
	// replicas don't report the same queues.
	QueueDue          *Gauge
	QueueScheduled    *Gauge
	QueueRunning      *Gauge
	QueueFailed       *Gauge
	QueuePaused       *Gauge
	QueueAutoPaused   *Gauge
	QueueOldestDueAge *Gauge

	// Schedules, counted by the leader.
	ScheduleRuns            *Counter
	ScheduleAttempts        *Counter
	ScheduleAttemptDuration *Histogram
	ScheduleFireLag         *Histogram

	// Read at scrape time by the leader, like the queue gauges.
	SchedulePaused      *Gauge
	ScheduleLastSuccess *Gauge
}

Workly is the set of metrics the server exports.

func New

func New() *Workly

Jump to

Keyboard shortcuts

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