metricsdocgen

command
v2.38.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 13 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.

README

Metrics Documentation Generator

This tool generates the Prometheus metrics documentation at docs/admin/integrations/prometheus.md.

How It Works

The documentation is generated from two metrics files:

  1. metrics (static, manually maintained)
  2. generated_metrics (auto-generated, do not edit)

These files are merged and used to produce the final documentation.

metrics (static)

Contains metrics that are not directly defined in the coder source code:

  • go_*: Go runtime metrics
  • process_*: Process metrics from prometheus/client_golang
  • promhttp_*: Prometheus HTTP handler metrics

[!Note] This file also contains edge cases where metric metadata cannot be accurately extracted by the scanner (e.g., labels determined by runtime logic). Static metrics take priority over generated metrics when both files contain the same metric name.

Edit this file to add metrics that should appear in the documentation but are not scanned from the coder codebase, or to manually override metrics where the scanner generates incorrect metadata (e.g., missing runtime-determined labels like in agent_scripts_executed_total).

generated_metrics (auto-generated)

Contains metrics extracted from the coder source code by the AST scanner (scanner/scanner.go).

Do not edit this file directly. It is regenerated by running:

make scripts/metricsdocgen/generated_metrics
Configuring the scanner

Configure these options in scanner/scanner.go:

  • Scan scope (scanDirs): Directories searched recursively for metric definitions. Add a directory when definitions live outside the existing scan scope. Test files are excluded.
  • Prefixes (metricPrefixes): Directory mappings for prefixes added by registerer wrappers, which the scanner does not trace. Add a mapping when a directory's metrics share such a prefix, without duplicating names already declared in Name, Namespace, or Subsystem. Mappings include subdirectories, with the most specific path taking priority. Update them when prefixes change or definitions move, and use canonical prefixes rather than deprecated aliases.
  • Exceptions (skipPaths): Files excluded from scanning. Maintain their metrics in the static file when the scanner cannot extract them correctly, including cases that cannot use a directory-wide prefix mapping.

Updating Metrics Documentation

To regenerate the documentation after code changes:

make docs/admin/integrations/prometheus.md

This will:

  • Run the scanner to update generated_metrics
  • Merge metrics and generated_metrics metric files
  • Update the documentation file

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package main provides a tool to scan Go source files and extract Prometheus metric definitions.
Package main provides a tool to scan Go source files and extract Prometheus metric definitions.

Jump to

Keyboard shortcuts

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