Skip to main content

Metrics

Each osapi component has a /metrics endpoint for Prometheus, on its own port. osapi collects metrics with OpenTelemetry. Each component has its own Prometheus registry. Thus each endpoint shows only the data of its component.

Endpoints​

Each component's metrics server exposes three endpoints:

EndpointDescription
/metricsPrometheus metrics in text exposition format
/healthLiveness probe. Always returns {"status":"ok"}
/health/readyReadiness probe. 200 when ready, 503 when not

The health probes need no authentication. They are always available when the metrics server is enabled.

KeyTypeDefaultEnvironmentDescription
controller.metrics.portint9090OSAPI_CONTROLLER_METRICS_PORTPort the metrics server listens on.
agent.metrics.portint9091OSAPI_AGENT_METRICS_PORTPort the metrics server listens on.
nats.server.metrics.portint9092OSAPI_NATS_SERVER_METRICS_PORTPort the metrics server listens on.

Application metrics reference​

osapi records all application metrics through OpenTelemetry, and exports them through the OTEL Prometheus exporter with the osapi namespace. The exporter adds the osapi_ prefix automatically. The output has the OTEL scope labels, for example otel_scope_name, so that you can find the source of a metric.

Each component also has the Go runtime metrics (goroutines, memory, GC) and the process metrics (CPU, memory, file descriptors).

MetricTypeLabelsComponentDescription
osapi_component_upgaugeallWhether the component is ready (1) or not (0).
osapi_subsystem_upgaugesubsystemallWhether a subsystem is healthy (1) or not (0).
osapi_heartbeat_age_secondsgaugeagentSeconds since last successful heartbeat write.
osapi_jobs_created_totalcountercontrollerTotal jobs submitted via API.
osapi_jobs_processed_totalcounterstatusagentTotal jobs processed.
osapi_jobs_activegaugeagentCurrently executing jobs.
osapi_job_duration_secondshistogramagentJob execution duration in seconds.
osapi_behavior_calls_totalcounterosapi_behavior_name, osapi_behavior_method, osapi_behavior_verb, osapi_behavior_outcomeagentBehavior method calls, by behavior, method and outcome.
osapi_behavior_duration_secondshistogramosapi_behavior_name, osapi_behavior_method, osapi_behavior_verbagentBehavior method duration in seconds.
osapi_behavior_changes_totalcounterosapi_behavior_name, osapi_behavior_method, osapi_behavior_verbagentBehavior writes that changed the host.

The osapi_subsystem_up gauge has a subsystem label that names its internal service, for example api, heartbeat, metrics, notifier, tracing or facts. A value of 1 means that the status of the subsystem is ok. A value of 0 means disabled or error.

The controller also has HTTP request metrics from the OTEL middleware, with the standard http.server.* names, for example http.server.request.duration and http.server.active_requests.

Each component records osapi_nats_client_operation_duration_seconds for each call that it makes to NATS. db_operation_name is the call, for example kv.get, kv.put or nats.publish. db_namespace is the bucket or the stream. A failed call also has error_type. A key, an object name and a subject are never labels, because they have no limit. A key that is not there is the answer of a read, not a failure, so it has no error_type.

The NATS component also has osapi_component_up and osapi_subsystem_up. NATS has its own monitoring.

Health probes​

Each metrics server also serves lightweight health probes on the same port. These are always unauthenticated.

Liveness (/health)​

Always returns 200 OK with {"status":"ok"} when the metrics server is running. Use this to detect hung or crashed processes.

Readiness (/health/ready)​

Returns 200 OK when the component is ready, or 503 Service Unavailable when it is not. Use this to gate traffic until the component has fully started.

Kubernetes example​

livenessProbe:
httpGet:
path: /health
port: 9090
initialDelaySeconds: 5
periodSeconds: 10

readinessProbe:
httpGet:
path: /health/ready
port: 9090
initialDelaySeconds: 5
periodSeconds: 10

Adjust the port to match the component (9090 for controller, 9091 for agent, 9092 for NATS).

Integration​

Point your Prometheus instance at each component:

# prometheus.yml
scrape_configs:
- job_name: 'osapi-controller'
static_configs:
- targets: ['localhost:9090']
- job_name: 'osapi-agent'
static_configs:
- targets: ['localhost:9091']
- job_name: 'osapi-nats'
static_configs:
- targets: ['localhost:9092']

Configuration​

You can enable or disable the metrics server of each component separately:

KeyTypeDefaultEnvironmentDescription
controller.metrics.enabledbooltrueOSAPI_CONTROLLER_METRICS_ENABLEDEnable the metrics endpoint.
controller.metrics.hoststring0.0.0.0OSAPI_CONTROLLER_METRICS_HOSTHost the metrics server binds to.
controller.metrics.portint9090OSAPI_CONTROLLER_METRICS_PORTPort the metrics server listens on.
controller.metrics.urlstringnone: where a person reaches it; empty shows the bind addressOSAPI_CONTROLLER_METRICS_URLWhere a person opens the metrics endpoint, shown by health beside the bind address.
controller.metrics.tls.enabledbooltrueOSAPI_CONTROLLER_METRICS_TLS_ENABLEDServe TLS on the port (HTTPS for the API and metrics), in place of plain text. Without cert_file and key_file, the API makes a self-signed certificate in controller.pki.key_dir; a metrics server and the NATS server need both.
controller.metrics.tls.cert_filestringnone: a certificate of the operator; empty is the API's self-signed certificateOSAPI_CONTROLLER_METRICS_TLS_CERT_FILEThe PEM certificate to serve, with its chain, such as one from tailscale cert or certbot. Set it with key_file, or neither for the self-signed certificate.
controller.metrics.tls.key_filestringnone: a certificate of the operator; empty is the API's self-signed certificateOSAPI_CONTROLLER_METRICS_TLS_KEY_FILEThe PEM private key of cert_file.
agent.metrics.enabledbooltrueOSAPI_AGENT_METRICS_ENABLEDEnable the metrics endpoint.
agent.metrics.hoststring0.0.0.0OSAPI_AGENT_METRICS_HOSTHost the metrics server binds to.
agent.metrics.portint9091OSAPI_AGENT_METRICS_PORTPort the metrics server listens on.
agent.metrics.urlstringnone: where a person reaches it; empty shows the bind addressOSAPI_AGENT_METRICS_URLWhere a person opens the metrics endpoint, shown by health beside the bind address.
agent.metrics.tls.enabledbooltrueOSAPI_AGENT_METRICS_TLS_ENABLEDServe TLS on the port (HTTPS for the API and metrics), in place of plain text. Without cert_file and key_file, the API makes a self-signed certificate in controller.pki.key_dir; a metrics server and the NATS server need both.
agent.metrics.tls.cert_filestringnone: a certificate of the operator; empty is the API's self-signed certificateOSAPI_AGENT_METRICS_TLS_CERT_FILEThe PEM certificate to serve, with its chain, such as one from tailscale cert or certbot. Set it with key_file, or neither for the self-signed certificate.
agent.metrics.tls.key_filestringnone: a certificate of the operator; empty is the API's self-signed certificateOSAPI_AGENT_METRICS_TLS_KEY_FILEThe PEM private key of cert_file.
nats.server.metrics.enabledbooltrueOSAPI_NATS_SERVER_METRICS_ENABLEDEnable the metrics endpoint.
nats.server.metrics.hoststring0.0.0.0OSAPI_NATS_SERVER_METRICS_HOSTHost the metrics server binds to.
nats.server.metrics.portint9092OSAPI_NATS_SERVER_METRICS_PORTPort the metrics server listens on.
nats.server.metrics.urlstringnone: where a person reaches it; empty shows the bind addressOSAPI_NATS_SERVER_METRICS_URLWhere a person opens the metrics endpoint, shown by health beside the bind address.
nats.server.metrics.tls.enabledbooltrueOSAPI_NATS_SERVER_METRICS_TLS_ENABLEDServe TLS on the port (HTTPS for the API and metrics), in place of plain text. Without cert_file and key_file, the API makes a self-signed certificate in controller.pki.key_dir; a metrics server and the NATS server need both.
nats.server.metrics.tls.cert_filestringnone: a certificate of the operator; empty is the API's self-signed certificateOSAPI_NATS_SERVER_METRICS_TLS_CERT_FILEThe PEM certificate to serve, with its chain, such as one from tailscale cert or certbot. Set it with key_file, or neither for the self-signed certificate.
nats.server.metrics.tls.key_filestringnone: a certificate of the operator; empty is the API's self-signed certificateOSAPI_NATS_SERVER_METRICS_TLS_KEY_FILEThe PEM private key of cert_file.

Set enabled: false to disable the metrics endpoint for a component. See the Configuration reference for the full list of settings and environment variable overrides.