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

Function NewMetrics

coderd/x/chatd/chatloop/metrics.go:45–113  ·  view source on GitHub ↗

NewMetrics creates a new Metrics instance registered with the given registerer.

(reg prometheus.Registerer)

Source from the content-addressed store, hash-verified

43// NewMetrics creates a new Metrics instance registered with the
44// given registerer.
45func NewMetrics(reg prometheus.Registerer) *Metrics {
46 factory := promauto.With(reg)
47 return &Metrics{
48 Chats: factory.NewGaugeVec(prometheus.GaugeOpts{
49 Namespace: metricsNamespace,
50 Subsystem: metricsSubsystem,
51 Name: "chats",
52 Help: "Number of chats being processed, by state.",
53 }, []string{"state"}),
54 MessageCount: factory.NewHistogramVec(prometheus.HistogramOpts{
55 Namespace: metricsNamespace,
56 Subsystem: metricsSubsystem,
57 Name: "message_count",
58 Help: "Number of messages in the prompt per LLM request.",
59 Buckets: prometheus.ExponentialBuckets(1, 2, 11), // 1, 2, 4, ..., 1024
60 }, []string{"provider", "model"}),
61 PromptSizeBytes: factory.NewHistogramVec(prometheus.HistogramOpts{
62 Namespace: metricsNamespace,
63 Subsystem: metricsSubsystem,
64 Name: "prompt_size_bytes",
65 Help: "Estimated byte size of the prompt per LLM request.",
66 Buckets: prometheus.ExponentialBuckets(1024, 4, 10), // 1KB .. 256MB
67 }, []string{"provider", "model"}),
68 ToolResultSizeBytes: factory.NewHistogramVec(prometheus.HistogramOpts{
69 Namespace: metricsNamespace,
70 Subsystem: metricsSubsystem,
71 Name: "tool_result_size_bytes",
72 Help: "Size in bytes of each tool execution result.",
73 Buckets: prometheus.ExponentialBuckets(64, 4, 9), // 64B .. 4MB
74 }, []string{"provider", "model", "tool_name"}),
75 ToolErrorsTotal: factory.NewCounterVec(prometheus.CounterOpts{
76 Namespace: metricsNamespace,
77 Subsystem: metricsSubsystem,
78 Name: "tool_errors_total",
79 Help: "Total tool calls that returned an error result.",
80 }, []string{"provider", "model", "tool_name"}),
81 TTFTSeconds: factory.NewHistogramVec(prometheus.HistogramOpts{
82 Namespace: metricsNamespace,
83 Subsystem: metricsSubsystem,
84 Name: "ttft_seconds",
85 Help: "Time-to-first-token: wall time from LLM request to first streamed chunk.",
86 Buckets: []float64{0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60},
87 }, []string{"provider", "model"}),
88 CompactionTotal: factory.NewCounterVec(prometheus.CounterOpts{
89 Namespace: metricsNamespace,
90 Subsystem: metricsSubsystem,
91 Name: "compaction_total",
92 Help: "Total compaction outcomes (only recorded when compaction was triggered or failed).",
93 }, []string{"provider", "model", "result"}),
94 StepsTotal: factory.NewCounterVec(prometheus.CounterOpts{
95 Namespace: metricsNamespace,
96 Subsystem: metricsSubsystem,
97 Name: "steps_total",
98 Help: "Total agentic loop steps across all chats.",
99 }, []string{"provider", "model"}),
100 StreamRetriesTotal: factory.NewCounterVec(prometheus.CounterOpts{
101 Namespace: metricsNamespace,
102 Subsystem: metricsSubsystem,

Calls

no outgoing calls