metric

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Component = &component.Component{
	Name: "runner.metric",
	Dependencies: component.Components{
		runner.Component,
	},
	Init: component.StepFunc(func(container container.Container) error {
		return container.Provide(NewMetric)
	}),
	PreExecute: component.StepFunc(func(container container.Container) error {
		return container.Invoke(func(r runner.Runner, middleware *Metric) {
			r.Use(middleware)
		})
	}),
}

Component is a ready-to-use Compogo component that automatically adds Prometheus metrics middleware to the application's runner.

It depends on runner.Component and registers itself during the PreRun phase. The exported metrics follow the naming convention:

compogo_runner_task{app="<app-name>"}

Usage:

compogo.WithComponents(
    runner.Component,
    metric.Component,  // ← adds Prometheus metrics to all tasks
)

Functions

This section is empty.

Types

type Metric

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

Metric is a middleware that increments a Prometheus counter for each task execution. It helps track how many tasks are being run and can be used for monitoring task activity.

func NewMetric

func NewMetric(appConfig *compogo.Config) *Metric

NewMetric creates a new Metric middleware instance. The appConfig provides the application name which is added as a label to the counter, allowing per-application metrics in multi-service environments.

The exported metric follows the naming convention:

compogo_runner_task{app="<app-name>"}

func (*Metric) Middleware

func (m *Metric) Middleware(task *runner.Task, next runner.Process) runner.Process

Middleware wraps a task's process function and increments the counter each time the task is executed. The counter is incremented regardless of whether the task succeeds or fails.

Jump to

Keyboard shortcuts

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