MCPcopy Index your code
hub / github.com/coder/coder / AgentStats

Function AgentStats

coderd/prometheusmetrics/prometheusmetrics.go:432–631  ·  view source on GitHub ↗

nolint:revive // This will be removed alongside the workspaceusage experiment

(ctx context.Context, logger slog.Logger, registerer prometheus.Registerer, db database.Store, initialCreateAfter time.Time, duration time.Duration, aggregateByLabels []string, usage bool)

Source from the content-addressed store, hash-verified

430
431// nolint:revive // This will be removed alongside the workspaceusage experiment
432func AgentStats(ctx context.Context, logger slog.Logger, registerer prometheus.Registerer, db database.Store, initialCreateAfter time.Time, duration time.Duration, aggregateByLabels []string, usage bool) (func(), error) {
433 if duration == 0 {
434 duration = defaultRefreshRate
435 }
436
437 if len(aggregateByLabels) == 0 {
438 aggregateByLabels = agentmetrics.LabelAgentStats
439 }
440
441 aggregateByLabels = filterAcceptableAgentLabels(aggregateByLabels)
442
443 metricsCollectorAgentStats := prometheus.NewHistogram(prometheus.HistogramOpts{
444 Namespace: "coderd",
445 Subsystem: "prometheusmetrics",
446 Name: "agentstats_execution_seconds",
447 Help: "Histogram for duration of agent stats metrics collection in seconds.",
448 Buckets: []float64{0.001, 0.005, 0.010, 0.025, 0.050, 0.100, 0.500, 1, 5, 10, 30},
449 })
450 err := registerer.Register(metricsCollectorAgentStats)
451 if err != nil {
452 return nil, err
453 }
454
455 agentStatsTxBytesGauge := NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{
456 Namespace: "coderd",
457 Subsystem: "agentstats",
458 Name: "tx_bytes",
459 Help: "Agent Tx bytes",
460 }, aggregateByLabels))
461 err = registerer.Register(agentStatsTxBytesGauge)
462 if err != nil {
463 return nil, err
464 }
465
466 agentStatsRxBytesGauge := NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{
467 Namespace: "coderd",
468 Subsystem: "agentstats",
469 Name: "rx_bytes",
470 Help: "Agent Rx bytes",
471 }, aggregateByLabels))
472 err = registerer.Register(agentStatsRxBytesGauge)
473 if err != nil {
474 return nil, err
475 }
476
477 agentStatsConnectionCountGauge := NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{
478 Namespace: "coderd",
479 Subsystem: "agentstats",
480 Name: "connection_count",
481 Help: "The number of established connections by agent",
482 }, aggregateByLabels))
483 err = registerer.Register(agentStatsConnectionCountGauge)
484 if err != nil {
485 return nil, err
486 }
487
488 agentStatsConnectionMedianLatencyGauge := NewCachedGaugeVec(prometheus.NewGaugeVec(prometheus.GaugeOpts{
489 Namespace: "coderd",

Callers 2

TestAgentStatsFunction · 0.92
enablePrometheusFunction · 0.92

Calls 13

WithLabelValuesMethod · 0.95
CommitMethod · 0.95
NewCachedGaugeVecFunction · 0.85
StopMethod · 0.65
ObserveDurationMethod · 0.65
ResetMethod · 0.65
RegisterMethod · 0.45
DoneMethod · 0.45

Tested by 1

TestAgentStatsFunction · 0.74