Documentation
¶
Index ¶
- Constants
- Variables
- func EchoHandler() echo.HandlerFunc
- func EchoMiddleware() echo.MiddlewareFunc
- func Handler() http.Handler
- func InitSchedulerTask(task string)
- func RecordSchedulerRun(task string, duration time.Duration, err error)
- func StartCollector(ctx *appContext.Context, provider AgentMetricsProvider, interval time.Duration)
- func StartServer(ctx *appContext.Context, listen string) *http.Server
- type AgentCount
- type AgentMetricsProvider
Constants ¶
const ( StatusSuccess = "success" StatusError = "error" )
Outcome labels of a background task run.
Variables ¶
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 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
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