This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/metrics/metrics.go
Jeffrey Smith c470037fb5
Some checks failed
CI/CD / detect-changes (push) Successful in 23s
CI/CD / test-sqlite (push) Failing after 20s
CI/CD / test-frontend (push) Failing after 21s
CI/CD / test-go-pg (push) Failing after 38s
CI/CD / build-and-deploy (push) Has been skipped
rebrand + purge orphaned frontend: Chat Switchboard → Switchboard Core
Branding: bulk rename across 50+ files (Go, JS, CSS, HTML, YAML, JSON,
shell scripts). Fix Helm chart description and git repo URLs.
Fix test helper taglines.

Admin surface: strip 14 gutted tabs (providers, models, personas,
roles, knowledge, memory, tasks, health, routing, capabilities,
channels, dashboard, usage, stats). Collapse to 4 categories:
People, Workflows, System, Monitoring.

Settings surface: strip 11 gutted tabs (models, personas, providers,
roles, knowledge, memory, usage, workflows, tasks, data, gitkeys).
Keep: general, appearance, profile, teams, connections, notifications.

Team-admin surface: strip 5 gutted tabs (personas, providers,
knowledge, tasks, usage). Keep: members, groups, connections,
workflows, settings, activity.

Components: delete chat-pane/ (13 files, 1938 lines) and
notes-pane/ (10 files, 2381 lines).

main.go: remove stale Health.Prune maintenance goroutine.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 10:28:09 +00:00

98 lines
3.9 KiB
Go

// Package metrics defines all Prometheus metrics for Switchboard Core.
// All metrics use the "switchboard_" prefix. Registered via promauto
// so they are available on the default registry's /metrics endpoint.
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// ── HTTP Request Metrics ────────────────────
var (
HTTPRequestsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "switchboard_http_requests_total",
Help: "Total HTTP requests by method, path pattern, and status code.",
}, []string{"method", "path_pattern", "status"})
HTTPRequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "switchboard_http_request_duration_seconds",
Help: "HTTP request latency in seconds.",
Buckets: []float64{0.01, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30},
}, []string{"method", "path_pattern"})
)
// ── WebSocket Metrics ───────────────────────
var WebSocketConnections = promauto.NewGauge(prometheus.GaugeOpts{
Name: "switchboard_websocket_connections",
Help: "Current number of active WebSocket connections.",
})
// ── Completion / Token Metrics ──────────────
var (
CompletionTokensTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "switchboard_completion_tokens_total",
Help: "Total tokens processed by direction (prompt|completion) and model.",
}, []string{"direction", "model_id"})
CompletionsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "switchboard_completions_total",
Help: "Total completion requests by provider, model, and status.",
}, []string{"provider_config_id", "model_id", "status"})
CompletionDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "switchboard_completion_duration_seconds",
Help: "Completion request latency (wall time including tool loops).",
Buckets: []float64{0.1, 0.5, 1, 2, 5, 10, 30, 60, 120},
}, []string{"provider_config_id", "model_id"})
)
// ── Provider Health ─────────────────────────
var ProviderStatus = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "switchboard_provider_status",
Help: "Provider health status: 0=unknown, 1=healthy, 2=degraded, 3=down.",
}, []string{"provider_config_id"})
// ── Database Pool Metrics ───────────────────
var (
DBOpenConnections = promauto.NewGauge(prometheus.GaugeOpts{
Name: "switchboard_db_open_connections",
Help: "Number of open database connections.",
})
DBInUseConnections = promauto.NewGauge(prometheus.GaugeOpts{
Name: "switchboard_db_in_use_connections",
Help: "Number of database connections currently in use.",
})
DBIdleConnections = promauto.NewGauge(prometheus.GaugeOpts{
Name: "switchboard_db_idle_connections",
Help: "Number of idle database connections.",
})
DBWaitCount = promauto.NewGauge(prometheus.GaugeOpts{
Name: "switchboard_db_wait_count_total",
Help: "Total number of connections waited for.",
})
DBWaitDuration = promauto.NewGauge(prometheus.GaugeOpts{
Name: "switchboard_db_wait_duration_seconds_total",
Help: "Total time blocked waiting for a new connection (seconds).",
})
)
// ── Task Scheduler Metrics ──────────────────
var TaskExecutionsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "switchboard_task_executions_total",
Help: "Total task executions by status (success|error).",
}, []string{"status"})
// ── Sandbox Metrics ─────────────────────────
var SandboxExecutionsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "switchboard_sandbox_executions_total",
Help: "Total Starlark sandbox executions by entry point and status.",
}, []string{"entry_point", "status"})