metrics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSuccess = "success"
	StatusError   = "error"
)

Outcome labels of a background task run.

Variables

View Source
var (
	// AgentErrorsGauge tracks the number of agents in error status per namespace/project
	AgentErrorsGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "flecto_agent_errors_total",
			Help: "Number of agents in error status (excluding offline agents)",
		},
		[]string{"namespace", "project"},
	)

	// AgentOnlineGauge tracks the number of online agents per namespace/project
	AgentOnlineGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "flecto_agent_online_total",
			Help: "Number of online agents",
		},
		[]string{"namespace", "project"},
	)

	// HTTPRequestsTotal counts HTTP requests
	HTTPRequestsTotal = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "flecto_http_requests_total",
			Help: "Total number of HTTP requests",
		},
		[]string{"method", "path", "status"},
	)

	// HTTPRequestDuration tracks HTTP request duration
	HTTPRequestDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "flecto_http_request_duration_seconds",
			Help:    "HTTP request duration in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"method", "path"},
	)

	// SchedulerTaskRunsTotal counts background task runs by outcome. A panic counts
	// as an error, so a task crashing every run never reads as healthy.
	SchedulerTaskRunsTotal = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "flecto_scheduler_task_runs_total",
			Help: "Total number of background task runs, by outcome",
		},
		[]string{"task", "status"},
	)

	// SchedulerTaskDuration tracks how long a background task run takes, which is
	// how a task drifting towards its timeout becomes visible before it hits it.
	// Buckets span sub-second to a quarter of an hour: these are batch jobs, not
	// requests.
	SchedulerTaskDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "flecto_scheduler_task_duration_seconds",
			Help:    "Background task run duration in seconds",
			Buckets: []float64{0.1, 0.5, 1, 5, 15, 60, 300, 900},
		},
		[]string{"task"},
	)

	// SchedulerTaskLastSuccessTimestamp is when a background task last succeeded.
	// It catches what a run counter cannot: a task that stopped running altogether
	// emits no error, it simply stops emitting - and its last success ages.
	SchedulerTaskLastSuccessTimestamp = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "flecto_scheduler_task_last_success_timestamp_seconds",
			Help: "Unix timestamp of the last successful run of a background task",
		},
		[]string{"task"},
	)
)

Functions

func EchoHandler

func EchoHandler() echo.HandlerFunc

EchoHandler returns an Echo handler for Prometheus metrics

func EchoMiddleware

func EchoMiddleware() echo.MiddlewareFunc

EchoMiddleware returns an Echo middleware that records HTTP metrics

func Handler

func Handler() http.Handler

Handler returns the Prometheus metrics HTTP handler

func InitSchedulerTask added in v0.2.0

func InitSchedulerTask(task string)

InitSchedulerTask publishes a task's counters before its first run. Without this a task that has never run is absent from /metrics, and an alerting rule matching nothing looks exactly like an alerting rule matching a healthy task.

func RecordSchedulerRun added in v0.2.0

func RecordSchedulerRun(task string, duration time.Duration, err error)

RecordSchedulerRun reports the outcome of one background task run.

func StartCollector

func StartCollector(ctx *appContext.Context, provider AgentMetricsProvider, interval time.Duration)

StartCollector starts a background goroutine that periodically updates agent metrics

func StartServer

func StartServer(ctx *appContext.Context, listen string) *http.Server

StartServer starts a dedicated metrics server on the specified address

Types

type AgentCount

type AgentCount struct {
	NamespaceCode string
	ProjectCode   string
	Status        commonTypes.AgentStatus
	Count         int64
}

AgentCount represents agent count for a namespace/project/status combination

type AgentMetricsProvider

type AgentMetricsProvider interface {
	GetAgentCounts(ctx context.Context, onlineThreshold time.Time) ([]AgentCount, error)
}

AgentMetricsProvider provides agent metrics data

func NewAgentMetricsProvider

func NewAgentMetricsProvider(agentService service.AgentService) AgentMetricsProvider

NewAgentMetricsProvider creates a new AgentMetricsProvider

Jump to

Keyboard shortcuts

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