opsmetrics

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package opsmetrics holds the operational metrics every role exports on /metrics (review 2026-11 OP-1): background jobs (depth, lag, failures by kind), messages handed to sending providers by adapter and result, webhook ingest lag, outgoing webhook deliveries and the database pool.

Counters are package variables, counted where the work happens; the queue gauges are read from the database at scrape time, at most every 15 seconds, so a busy Prometheus never loads the database.

Index

Constants

View Source
const (
	Accepted = "accepted"
	Rejected = "rejected"
	Deferred = "deferred"
	Failed   = "failed"
)

Message results.

Variables

View Source
var (
	// AssistantTTFTOverhead is what the server adds before a turn's first
	// answer token reaches the database, the provider's own time taken out.
	AssistantTTFTOverhead = prometheus.NewHistogram(prometheus.HistogramOpts{
		Name: "reputecast_ai_assistant_ttft_overhead_seconds",
		Help: "Server time before an assistant turn's first answer token is committed, without the provider: from the person's message committed to the first delta committed, " +
			"minus the provider's time from the request sent to its first token. Counts turns whose first model request streams text; includes the job's wait for a worker and a slot, " +
			"the context assembly, the budget reservation and writing the first delta.",
		Buckets: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10, 30},
	})
	// AssistantStream is how long a turn's model request streamed.
	AssistantStream = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name: "reputecast_ai_assistant_stream_seconds",
		Help: "Duration of an assistant model request, from sending it to the provider's last event or the stream's end, by kind (answer, summary) and outcome " +
			"(answered, refused, error, cancelled).",
		Buckets: []float64{.1, .25, .5, 1, 2.5, 5, 10, 30, 60, 120, 300},
	}, []string{"kind", "outcome"})
	// AssistantTokens counts the tokens the provider reported.
	AssistantTokens = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "reputecast_ai_assistant_tokens_total",
		Help: "Tokens of assistant model requests as providers reported them, by direction (input, output). Requests whose usage wasn't reported aren't counted.",
	}, []string{"direction"})
	// AssistantToolCalls counts the tool calls models asked for.
	AssistantToolCalls = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "reputecast_ai_assistant_tool_calls_total",
		Help: "Tool calls assistant models asked for, by kind (reputecast, mcp_read, mcp_write) and outcome (ok, not_available, forbidden, not_found, tool_limit, denied, " +
			"outcome_unknown, timeout, error).",
	}, []string{"kind", "outcome"})
	// MCPCall is how long calls of MCP servers' tools took.
	MCPCall = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "reputecast_mcp_call_seconds",
		Help:    "Duration of calls of remote MCP servers' tools, connection included, by result (ok, error).",
		Buckets: []float64{.05, .1, .25, .5, 1, 2.5, 5, 10, 30},
	}, []string{"result"})
	// MCPCallErrors counts failed calls by code.
	MCPCallErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "reputecast_mcp_call_errors_total",
		Help: "Failed calls of remote MCP servers' tools, by code (mcp_unreachable, mcp_sign_in, mcp_timeout, mcp_too_large, mcp_tool_changed, mcp_tool_blocked, tool_error, " +
			"forbidden, error).",
	}, []string{"code"})
	// AssistantStreams counts the thread streams this process serves.
	AssistantStreams = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "reputecast_ai_assistant_streams",
		Help: "Assistant thread event streams (SSE) this process serves now.",
	})
	// AssistantEventLag is how late a stream writes an event.
	AssistantEventLag = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name: "reputecast_ai_assistant_event_lag_seconds",
		Help: "Time from an assistant thread event's insert in its committing transaction to an open stream writing it to its client, by kind (turn, delta, message, usage, tool, " +
			"confirmation). Events a stream catches up on when it (re)connects aren't counted.",

		Buckets: []float64{.001, .0025, .005, .01, .02, .03, .04, .05, .06, .07, .08, .09, .1, .11, .12, .13, .14, .15, .175, .2, .25, .3, .5, 1, 2.5},
	}, []string{"kind"})
)

The AI assistant's metrics (B6). Their labels are bounded sets of constants: never content, ids or names (assistant brief §3.7).

View Source
var (
	// ProviderMessages counts the messages handed to sending providers:
	// accepted, rejected (permanently), deferred (a temporary refusal,
	// retried) or failed (the whole call failed).
	ProviderMessages = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "reputecast_provider_messages_total",
		Help: "Messages handed to sending providers, by adapter and result (accepted, rejected, deferred, failed).",
	}, []string{"provider", "result"})
	// ProviderCalls counts send calls to providers, by adapter and result
	// (ok or error).
	ProviderCalls = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "reputecast_provider_calls_total",
		Help: "Send calls to sending providers, by adapter and result (ok, error).",
	}, []string{"provider", "result"})
	// JobFailures counts failed job attempts by kind: retried, discarded
	// (out of attempts) or panicked.
	JobFailures = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "reputecast_job_failures_total",
		Help: "Failed background job attempts, by kind and outcome (retry, discarded, panic).",
	}, []string{"kind", "outcome"})
	// WebhookDeliveries counts attempts to deliver outgoing webhooks.
	WebhookDeliveries = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "reputecast_webhook_deliveries_total",
		Help: "Outgoing webhook delivery attempts, by result (delivered, retrying, dead).",
	}, []string{"result"})
	// IngestRequests counts provider webhook requests received.
	IngestRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "reputecast_ingest_requests_total",
		Help: "Provider webhook requests received, by channel (email, sms, whatsapp) and result (stored, rejected).",
	}, []string{"channel", "result"})
)

Counters, counted where the work happens.

Functions

func MCPErrorCode

func MCPErrorCode(outcome string) string

MCPErrorCode is a failed MCP call's code label.

func Register

func Register(reg prometheus.Registerer, pool *pgxpool.Pool, queues ...string)

Register adds the counters and the database collectors to reg. queues are the job queues whose lag always shows, 0 when nothing waits.

func ToolOutcome

func ToolOutcome(code string) string

ToolOutcome is a tool call's outcome label for its result code ("" is ok): the codes a person or operator acts on, anything else error.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL