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

Function PrometheusMetricsHandler

agent/agent.go:2529–2550  ·  view source on GitHub ↗
(prometheusRegistry *prometheus.Registry, logger slog.Logger)

Source from the content-addressed store, hash-verified

2527}
2528
2529func PrometheusMetricsHandler(prometheusRegistry *prometheus.Registry, logger slog.Logger) http.Handler {
2530 return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
2531 w.Header().Set("Content-Type", "text/plain")
2532
2533 // Based on: https://github.com/tailscale/tailscale/blob/280255acae604796a1113861f5a84e6fa2dc6121/ipn/localapi/localapi.go#L489
2534 clientmetric.WritePrometheusExpositionFormat(w)
2535
2536 metricFamilies, err := prometheusRegistry.Gather()
2537 if err != nil {
2538 logger.Error(context.Background(), "prometheus handler failed to gather metric families", slog.Error(err))
2539 return
2540 }
2541
2542 for _, metricFamily := range metricFamilies {
2543 _, err = expfmt.MetricFamilyToText(w, metricFamily)
2544 if err != nil {
2545 logger.Error(context.Background(), "expfmt.MetricFamilyToText failed", slog.Error(err))
2546 return
2547 }
2548 }
2549 })
2550}
2551
2552// SSHKeySeed converts an owner userName, workspaceName and agentName to an int64 hash.
2553// This uses the FNV-1a hash algorithm which provides decent distribution and collision

Callers 2

workspaceAgentFunction · 0.92
apiHandlerMethod · 0.85

Calls 3

SetMethod · 0.65
HeaderMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected