Agents tracks the total number of workspaces with labels on status.
(ctx context.Context, logger slog.Logger, registerer prometheus.Registerer, db database.Store, coordinator *atomic.Pointer[tailnet.Coordinator], derpMapFn func() *tailcfg.DERPMap, agentInactiveDisconnectTimeout, duration time.Duration)
| 246 | |
| 247 | // Agents tracks the total number of workspaces with labels on status. |
| 248 | func Agents(ctx context.Context, logger slog.Logger, registerer prometheus.Registerer, db database.Store, coordinator *atomic.Pointer[tailnet.Coordinator], derpMapFn func() *tailcfg.DERPMap, agentInactiveDisconnectTimeout, duration time.Duration) (func(), error) { |
| 249 | if duration == 0 { |
| 250 | duration = defaultRefreshRate |
| 251 | } |
| 252 | |
| 253 | agentsGauge := NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
| 254 | Namespace: "coderd", |
| 255 | Subsystem: "agents", |
| 256 | Name: "up", |
| 257 | Help: "The number of active agents per workspace.", |
| 258 | }, []string{agentmetrics.LabelUsername, agentmetrics.LabelWorkspaceName, agentmetrics.LabelTemplateName, "template_version"})) |
| 259 | err := registerer.Register(agentsGauge) |
| 260 | if err != nil { |
| 261 | return nil, err |
| 262 | } |
| 263 | |
| 264 | agentsConnectionsGauge := NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
| 265 | Namespace: "coderd", |
| 266 | Subsystem: "agents", |
| 267 | Name: "connections", |
| 268 | Help: "Agent connections with statuses.", |
| 269 | }, []string{agentmetrics.LabelAgentName, agentmetrics.LabelUsername, agentmetrics.LabelWorkspaceName, "status", "lifecycle_state", "tailnet_node"})) |
| 270 | err = registerer.Register(agentsConnectionsGauge) |
| 271 | if err != nil { |
| 272 | return nil, err |
| 273 | } |
| 274 | |
| 275 | agentsConnectionLatenciesGauge := NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
| 276 | Namespace: "coderd", |
| 277 | Subsystem: "agents", |
| 278 | Name: "connection_latencies_seconds", |
| 279 | Help: "Agent connection latencies in seconds.", |
| 280 | }, []string{agentmetrics.LabelAgentName, agentmetrics.LabelUsername, agentmetrics.LabelWorkspaceName, "derp_region", "preferred"})) |
| 281 | err = registerer.Register(agentsConnectionLatenciesGauge) |
| 282 | if err != nil { |
| 283 | return nil, err |
| 284 | } |
| 285 | |
| 286 | agentsAppsGauge := NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
| 287 | Namespace: "coderd", |
| 288 | Subsystem: "agents", |
| 289 | Name: "apps", |
| 290 | Help: "Agent applications with statuses.", |
| 291 | }, []string{agentmetrics.LabelAgentName, agentmetrics.LabelUsername, agentmetrics.LabelWorkspaceName, "app_name", "health"})) |
| 292 | err = registerer.Register(agentsAppsGauge) |
| 293 | if err != nil { |
| 294 | return nil, err |
| 295 | } |
| 296 | |
| 297 | metricsCollectorAgents := prometheus.NewHistogram(prometheus.HistogramOpts{ |
| 298 | Namespace: "coderd", |
| 299 | Subsystem: "prometheusmetrics", |
| 300 | Name: "agents_execution_seconds", |
| 301 | Help: "Histogram for duration of agents metrics collection in seconds.", |
| 302 | Buckets: []float64{0.001, 0.005, 0.010, 0.025, 0.050, 0.100, 0.500, 1, 5, 10, 30}, |
| 303 | }) |
| 304 | err = registerer.Register(metricsCollectorAgents) |
| 305 | if err != nil { |