metrics

package
v0.110.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 4 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 metrics holds muster's Prometheus instrumentation. Everything here is registered on the default registry and exposed at /metrics.

πŸ”΄ THIS IS A SUBSET OF THE PACKAGE IT WAS CARVED FROM, AND THE OMISSIONS ARE THE POINT. The project muster was extracted from instrumented both products out of one file: permission decisions, Web Push delivery, auto-approve windows, the attention queue, suggestion generation and a transcript archive β€” none of which muster owns. Copying them would have shipped counters that can only ever read zero, and a metric that is structurally incapable of moving is worse than a missing one: it reads on a dashboard as "this subsystem is quiet" rather than "this subsystem is not here". Those metrics stayed with the routing service. If muster later grows one of those concerns, the counter arrives with it.

πŸ”΄ CARDINALITY RULE, APPLIED THROUGHOUT: every label below is drawn from a CLOSED Go vocabulary. No identifier that a producer can mint β€” a session id, a task id, an agent name, a free-form tag value, a raw request path β€” may ever become a label. Each one is an unbounded series and a leak of somebody else's identifier into a metrics store that is usually less protected than the database. Where that rule is easy to break by accident, the declaration says so at its own site.

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var (
	// BuildInfo is a constant gauge carrying the running version as a label.
	BuildInfo = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name: "muster_build_info",
		Help: "Build info; value is always 1, the version is a label.",
	}, []string{"version"})

	// Panics counts recovered panics (HTTP handlers + background goroutines) β€” a
	// nonzero value is always worth alerting on.
	Panics = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_panics_total",
		Help: "Recovered panics by source.",
	}, []string{"source"})

	// PushDelivery counts Web Push delivery attempts, one per DEVICE per
	// notification, by result:
	//   ok      β€” the push service accepted it (2xx)
	//   expired β€” the push service said the subscription is gone (404/410);
	//             the device was pruned
	//   failed  β€” a transport error or any other status; the device's
	//             fail_count went up
	//   disallowed β€” the device's push service is no longer allowed (its host
	//             left MUSTER_PUSH_EXTRA_HOSTS); nothing was sent and the
	//             device was pruned
	//   oversize β€” a paired phone's payload v2 was refused before sending: it
	//             would not fit in ntfy's 4096-byte message (push.ErrNativeTooLarge)
	// A notification to an owner with no devices counts nothing. The owner is
	// deliberately NOT a label (an identifier β€” see the cardinality rule); the
	// per-owner line is in the log (`push: delivered … owner=<id>`).
	PushDelivery = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_push_delivery_total",
		Help: "Web Push delivery attempts by result (ok|expired|failed|disallowed|oversize).",
	}, []string{"result"})

	// PushSuppressed counts notifications NOT sent, one per notification (not
	// per device), by reason:
	//   muted     β€” the owner turned that event off on /account
	//   throttled β€” the owner's per-owner rate cap was reached
	// A rising `throttled` is the amplification signal: something is producing
	// notifications faster than a person can read them.
	PushSuppressed = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_push_suppressed_total",
		Help: "Web Push notifications not sent, by reason (muted|throttled).",
	}, []string{"reason"})

	// MirrorAskTyping counts answers muster typed into a mirrored session's
	// AskUserQuestion picker, by outcome:
	//   typed        β€” every key landed (the CLI's record says whose answer won)
	//   not-sent     β€” refused before the host was asked (offline, step-up, …)
	//   no-picker    β€” the picker was gone (answered or dismissed in the terminal)
	//   touched      β€” someone was answering in the terminal; nothing typed
	//   unreadable   β€” the host could not read the question off the screen as
	//                  the one registered (NOT someone answering it): a parse
	//                  or registration mismatch, or a picker taller than the
	//                  pane β€” worth a look, like unrecognised
	//   busy         β€” another answer was being typed into that pane
	//   lost         β€” the picker changed mid-way; stopped, nothing submitted
	//   unrecognised β€” the host could not read the picker: Claude Code's layout
	//                  has probably changed β€” ANY of these is worth a look
	//                  (`make test-liveclaude`)
	//   unsupported  β€” the host cannot type answers
	//   timeout, error β€” the host's outcome never came back
	MirrorAskTyping = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_mirror_ask_typing_total",
		Help: "Answers typed into a mirrored session's AskUserQuestion picker, by outcome.",
	}, []string{"result"})

	// AgentProvision counts agent provisioning attempts.
	AgentProvision = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_agent_provision_total",
		Help: "Agent provision attempts by result (ok|failed).",
	}, []string{"result"})

	AgentProvisionDuration = promauto.NewHistogram(prometheus.HistogramOpts{
		Name:    "muster_agent_provision_duration_seconds",
		Help:    "Agent provision wall time, end to end.",
		Buckets: []float64{1, 5, 15, 30, 60, 120, 300},
	})

	// AgentKickoffResend counts kickoff recoveries after the container that
	// received the message died (out-of-memory kill, eviction, node drain), by
	// outcome:
	//   resent    β€” a re-send was launched against the replacement gateway
	//   exhausted β€” the re-send budget was spent and the agent was errored
	//
	// `exhausted` is the alertable one: it means a workspace is dying repeatedly
	// before it can start work β€” a memory limit too low for a real repository
	// clone is the shape that motivated this counter. A nonzero `resent` with no
	// `exhausted` is the system self-healing as designed.
	AgentKickoffResend = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_agent_kickoff_resend_total",
		Help: "Kickoff re-deliveries after the receiving container died (resent|exhausted).",
	}, []string{"result"})

	// AgentKickoffClaim counts outcomes of the CROSS-PROCESS kickoff claim β€” the
	// guard that stops two replicas from both kicking off one agent during a
	// rolling deploy:
	//   won                     β€” this process took the claim and ran the kickoff
	//   lost                    β€” another process held it; this kickoff was skipped
	//   error                   β€” the claim query failed; the kickoff was skipped
	//                             (FAIL CLOSED β€” the reconciler retries)
	//   renew_lost              β€” a renewal found the claim no longer ours, i.e.
	//                             a peer took it while our turn was still running
	//   renew_error             β€” a renewal round-trip failed (the claim is still
	//                             ours until the TTL; three in a row loses it)
	//   shutdown_released       β€” a claim released on the SIGTERM path
	//   shutdown_release_failed β€” that release errored; the claim waits out the TTL
	//   stale_swept             β€” a claim from a previous incarnation of this host
	//                             cleared at startup
	//
	// πŸ”΄ THIS COUNTER MAY BE THE ONLY OBSERVABILITY THIS MECHANISM HAS. The log
	// lines beside each Inc() live in the process's stdout, which rolls away with
	// the pod on every deploy unless something is shipping logs. A deployment
	// that scrapes metrics but does not collect logs β€” a common and entirely
	// reasonable shape β€” can observe neither a duplicate-kickoff bug nor its fix
	// without this.
	//
	// `renew_lost` is the alertable one: it means two kickoffs for one agent are
	// genuinely running concurrently. `lost` is the mechanism working as designed
	// and should be rare-but-nonzero around deploys; a `lost` of exactly zero
	// forever is weak evidence the claim is never contended, not that it works.
	AgentKickoffClaim = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_agent_kickoff_claim_total",
		Help: "Cross-process kickoff claim outcomes (won|lost|error|renew_lost|renew_error|shutdown_released|shutdown_release_failed|stale_swept).",
	}, []string{"result"})

	// TasksCreated counts tasks created through the HTTP API, by their derived
	// producer source.
	//
	// πŸ”΄ THE `source` LABEL IS BOUNDED BY A CLOSED ALLOWLIST IN THE API LAYER, not
	// by whatever the request carried. Deriving it from an Origin header or a
	// user agent directly would let any caller mint a new series.
	TasksCreated = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_tasks_created_total",
		Help: "Tasks created via the HTTP API, by derived source (a closed allowlist).",
	}, []string{"source"})

	// RoutingTags counts routing (reserved-namespace) tags written onto tasks.
	//
	// πŸ”΄ CARDINALITY RULE: the ONLY label is the reserved NAMESPACE, drawn from
	// the closed Go allowlist notes.RoutingNamespaces(). A tag's VALUE and any
	// free-form tag must NEVER reach a Prometheus label: free-form tags are
	// user/producer text and can carry repository or project names, so they would
	// blow up the label space and leak identifiers into metrics.
	RoutingTags = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_task_routing_tags_total",
		Help: "Routing tags written onto tasks, by reserved namespace ONLY β€” never the tag value.",
	}, []string{"namespace"})

	// TaskSessionLinks counts task-thread links that CHANGED β€” a session joining
	// a task's thread, or its role being upgraded. A repeat touch that only moves
	// last_seen_at is NOT counted, so this measures thread growth rather than
	// hook traffic.
	//
	// πŸ”΄ CARDINALITY RULE, same discipline as RoutingTags: the ONLY label is
	// `role`, drawn from the closed three-value vocabulary
	// notes.RoleRead|RoleWorked|RoleCreated. The SESSION ID must NEVER become a
	// label β€” it is unbounded producer-supplied text, one new series per session.
	TaskSessionLinks = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_task_session_links_total",
		Help: "Task-thread links created or upgraded, by role ONLY (read|worked|created) β€” never the session id.",
	}, []string{"role"})

	// TaskSessionLinksSkipped counts task-thread links that were NOT recorded, by
	// a closed two-value reason: `thread_full` (the task already carried
	// notes.MaxTaskSessions created/worked links, so a `read` breadcrumb was
	// dropped) or `error` (a store failure).
	//
	// πŸ”΄ IT EXISTS BECAUSE THE FAILURE IS DELIBERATELY SILENT TO THE CALLER. The
	// cap is advisory β€” a provenance breadcrumb must never break the operation it
	// annotates β€” so a skipped link produces a normal 200. Without this counter
	// the only trace would be a log line, and "the thread quietly stopped
	// growing" would be indistinguishable from "nothing touched this task".
	TaskSessionLinksSkipped = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_task_session_links_skipped_total",
		Help: "Task-thread links NOT recorded, by reason ONLY (thread_full|error) β€” never the session id.",
	}, []string{"reason"})

	// FlowJobs counts browser-flow job transitions (internal/flows), by flow and
	// outcome.
	//
	// πŸ”΄ CARDINALITY RULE: `flow` is a name from the COMPILED-IN catalogue
	// (flows.Catalogue β€” two entries today, and an enqueue naming anything else
	// is refused before it is counted), and `outcome` is the closed vocabulary
	// enqueued|claimed|requeued|done|failed|needs_operator|expired|cancelled,
	// plus an agent request's requested|approved|denied (migration 0014).
	// A job id, host, instance or any parameter must NEVER become a label.
	FlowJobs = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_flow_jobs_total",
		Help: "Browser-flow job transitions, by catalogue flow name and outcome ONLY β€” never a job id, host or parameter.",
	}, []string{"flow", "outcome"})

	// The memo relay (internal/memorelay): what each agent's check, each listener
	// call and each delivery came to.
	//
	// πŸ”΄ CARDINALITY RULE: `result` is a closed vocabulary compiled into
	// internal/memorelay (its Result* and Outcome* constants and upstreamResult).
	// An agent name, a scope, a memo id or anything a listener sent must NEVER
	// become a label.
	MemoRelayAgentChecks = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_memo_relay_agent_checks_total",
		Help: "Memo relay: agents classified per tick, by result ONLY (eligible, or why an agent is sent nothing).",
	}, []string{"result"})
	MemoRelayUpstream = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_memo_relay_upstream_total",
		Help: "Memo relay: calls to the cairn memo listener, by result ONLY β€” including the ones NOT sent (not_yet, backed_off, scope_backed_off).",
	}, []string{"result"})
	MemoRelayDeliveries = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_memo_relay_deliveries_total",
		Help: "Memo relay: delivery attempts to agents, by result ONLY β€” never an agent, scope or memo id.",
	}, []string{"result"})
)
View Source
var (
	// OpenPhase is the server's half of opening a session, by view
	// (mirror_view | mirror_terminal | agent) and phase:
	//   document     β€” the page's handler, request in to body written
	//   first_batch  β€” a rendered view's socket, upgrade to its first batch
	//                  written to the browser (resume or backfill)
	//   first_output β€” a terminal's socket, upgrade to its first bytes written
	OpenPhase = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "muster_open_phase_seconds",
		Help:    "Server-side phases of opening a session, by view and phase (closed vocabularies).",
		Buckets: []float64{0.01, 0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 20, 40},
	}, []string{"view", "phase"})

	// MirrorHubRoundTrip is one request to a mirror host, frame written to
	// answer read, by op (watch: to the first batch; attach: to the first
	// output; paste, scroll, catalog, answer, cancel_ask, hermes_answer,
	// subagent_tail: to the host's answer) and reason (mirror.Reason).
	MirrorHubRoundTrip = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "muster_mirror_hub_roundtrip_seconds",
		Help:    "A request to a mirror host, frame written to answer read, by op and reason.",
		Buckets: []float64{0.01, 0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 20, 40},
	}, []string{"op", "reason"})

	// ViewDisconnects counts a session view's socket ENDING, by view and
	// reason (mirror.Reason's vocabulary, plus client_left when the browser
	// went away first). It is the server's half of "the session
	// disconnected"; the page reports its own half through the browser
	// telemetry.
	ViewDisconnects = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "muster_view_disconnects_total",
		Help: "Session view sockets ended, by view and reason (closed vocabularies).",
	}, []string{"view", "reason"})
)

---- opening a session (docs/telemetry.md) --------------------------------

πŸ”΄ CARDINALITY RULE, AGAIN: `view`, `phase`, `op` and `reason` are each a closed vocabulary compiled into this module (the constants beside each Observe* below and mirror.Reason). A host, a session, a window, an agent name or a trace id must NEVER become a label β€” the per-open log line (`open view=…`) carries those, with the trace id that finds the trace.

View Source
var (
	// OfficerErrorSlots counts officer instance slots held by an instance in
	// error: the officer runs below target until it recovers or an operator acts.
	OfficerErrorSlots = promauto.NewGauge(prometheus.GaugeOpts{
		Name: "muster_officer_error_slots",
		Help: "Officer instance slots held by an instance in error (not restarted; the officer runs below target).",
	})
	// OfficerHQFaults counts officers whose HQ answers a PERMANENT refusal
	// (401/403/404: a revoked token, HQ without the officer API): a
	// configuration fault, not an outage. Their instances are scaled to zero.
	OfficerHQFaults = promauto.NewGauge(prometheus.GaugeOpts{
		Name: "muster_officer_hq_faults",
		Help: "Officers whose HQ refuses them permanently (401/403/404); their instances are scaled to zero.",
	})
)

The officer runtime (internal/officers). Deliberately UNLABELLED: an officer id is operator-configured, but a label per officer is still an identifier in a series name, and the operator needs "something is wrong", with the log line naming which officer. Each is the loop's whole-process total, set after every pass.

Functions ΒΆ

func ObserveHTTP ΒΆ

func ObserveHTTP(route, method string, code int, d time.Duration)

ObserveHTTP records one HTTP request's matched route pattern, method, status, and duration.

πŸ”΄ `route` MUST BE THE ROUTE PATTERN, NEVER THE REQUEST PATH. The pattern ("GET /api/tasks/{id}") is drawn from the mux's own finite route table, so the label space is bounded by the size of that table. The raw path carries ids and sometimes tokens and is unbounded. Callers pass "unmatched" on the 404 path for exactly this reason.

Types ΒΆ

This section is empty.

Jump to

Keyboard shortcuts

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