Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions docs-site/content/kagent/main/observability/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ author: kagent.dev

### Enable the metrics endpoint

The controller serves its metrics over HTTPS, and accepts a scrape only from a ServiceAccount that holds the `<fullname>-metrics-reader` ClusterRole. Enabling the endpoint creates a dedicated metrics Service and that ClusterRole.
By default, the controller serves its metrics over HTTPS, and accepts a scrape only from a ServiceAccount that is bound to the `<fullname>-metrics-reader` ClusterRole. Enabling the endpoint creates a dedicated metrics Service and the metrics role-based access control (RBAC) resources.

```yaml
controller:
Expand All @@ -23,12 +23,23 @@ config:
secure: true
```

These two sections divide the listener from its Kubernetes packaging. `config.metrics` sets the address that the controller binds and whether it serves over HTTPS. `controller.metrics` creates the Service, the ClusterRoles, and the optional ServiceMonitor. Setting `controller.metrics.enabled` to `false` overrides `config.metrics.bindAddress` with `0`, which disables the listener as well. Change the port through `config.metrics.bindAddress`, because the chart derives the Service `targetPort` and the pod `containerPort` from it at template time.
These two sections divide the listener from its Kubernetes packaging. `config.metrics` sets the address that the controller binds and whether it serves over HTTPS. `controller.metrics` creates the Service and the optional ServiceMonitor. When `config.metrics.secure` is set to `true`, it also creates the metrics ClusterRoles and ClusterRoleBinding. When `controller.metrics.enabled` is set to `false`, the chart overrides `config.metrics.bindAddress` with `0`. The `0` value also turns off the listener. The chart derives the Service `targetPort` and the pod `containerPort` from `config.metrics.bindAddress` at template time, so to change the port, set `config.metrics.bindAddress`.

To serve metrics over plain HTTP without authentication or authorization, set `config.metrics.secure` to `false`. With this setting, the chart omits the metrics RBAC resources, including when `rbac.namespaces` or `global.watchNamespaces` restricts the installation to specific namespaces. The Service keeps port `8443`, and the name of the port changes from `https` to `http-metrics`.

```yaml
controller:
metrics:
enabled: true
config:
metrics:
secure: false
```

Grant your Prometheus instance access in one of the following ways.

- **With the Prometheus Operator**: Set `controller.metrics.serviceMonitor.enabled` to `true`. The chart creates a ServiceMonitor for the metrics Service. Also set `controller.metrics.serviceMonitor.prometheusServiceAccount.name` and `.namespace` to the ServiceAccount that Prometheus runs as, and the chart binds the metrics reader ClusterRole to it. The chart renders the ServiceMonitor only when the cluster serves the `monitoring.coreos.com/v1` API. For an example, see [OTel stack]({{< link path="observability/otel-stack#send-kagent-telemetry-to-the-collector" >}}).
- **Without the Prometheus Operator**: Bind the `<fullname>-metrics-reader` ClusterRole to the Prometheus ServiceAccount yourself, and add a scrape job for the `<fullname>-controller-metrics` Service on port `8443`. The job must use HTTPS, send the ServiceAccount token, and skip verification of the controller's self-signed certificate. For an example, see [Lightweight OTel stack]({{< link path="observability/lightweight-otel-stack#install-prometheus" >}}).
- **With the Prometheus Operator**: Set `controller.metrics.serviceMonitor.enabled` to `true`. The chart creates a ServiceMonitor for the metrics Service. When `config.metrics.secure` is set to `true`, also set `controller.metrics.serviceMonitor.prometheusServiceAccount.name` and `.namespace` to the ServiceAccount that Prometheus runs as, and the chart binds the metrics reader ClusterRole to it. The chart renders the ServiceMonitor only when the cluster serves the `monitoring.coreos.com/v1` API. For an example, see [OTel stack]({{< link path="observability/otel-stack#send-kagent-telemetry-to-the-collector" >}}).
- **Without the Prometheus Operator**: Add a scrape job for the `<fullname>-controller-metrics` Service on port `8443`. When `config.metrics.secure` is set to `true`, bind the `<fullname>-metrics-reader` ClusterRole to the Prometheus ServiceAccount yourself. The job must use HTTPS, send the ServiceAccount token, and skip verification of the controller's self-signed certificate. When `config.metrics.secure` is set to `false`, the job uses plain HTTP and does not send a token. For an example, see [Lightweight OTel stack]({{< link path="observability/lightweight-otel-stack#install-prometheus" >}}).

### Metric reference

Expand All @@ -45,7 +56,6 @@ Besides the standard Go runtime and process metrics, the controller reports the
| `kagent_runtime_revision_gc_pending` | Gauge | Runtime revisions that the last successful discovery found eligible for cleanup. The controller reports a cached count, so a scrape does not make a database or network call. The metric is absent until a discovery succeeds, and `0` reports a discovery that matched nothing. A failed discovery holds the previous value rather than clearing it. |
| `kagent_runtime_revision_gc_duration_seconds` | Histogram | Time that one cleanup attempt takes, by the `kagent_gc_stage` label: `discovery` or `collection`. A `discovery` attempt covers the database query that lists every revision eligible for cleanup, and it updates `kagent_runtime_revision_gc_pending`. A `collection` attempt covers the database claim, the Agent Substrate read and deletion, and the database finalization. A failed attempt carries an `error_type` label holding a gRPC status code name, or `_OTHER` for every other failure, so the series that carry the label give both the failure rate and the reason. |

{{% version exclude-if="1.0.x,0.x" %}}
The controller also reports the following counters.

| Metric | Type | Measures |
Expand All @@ -54,7 +64,6 @@ The controller also reports the following counters.
| `kagent_push_delivery_claimed_total` | Counter | Push delivery attempts that the controller acquired before delivery I/O. Push retries count as separate attempts, and a claim counts even when later delivery fails. |

The session quiescence and push delivery counters carry the `kagent_worker_trigger` label. The label value is `signal`, `recovery`, `startup`, `retry`, or `backlog`. Use `recovery` to count timer-driven discoveries of work. Follow-on claims use `backlog`, including worker handoffs and push delivery capacity refills. Empty scans and failed claim requests do not increase either counter. When the recovery timer finds work, the controller also writes the `recovery scan found work` log message with the `operation`, `recovery_interval_seconds`, and first `session_id` or `registration_id` fields.
{{% /version %}}

The Agent Substrate `atecontroller` component reports the same `controller_runtime_*` and `workqueue_*` metrics for its own reconcilers. To keep the two apart in a query, filter by the scrape job, such as `job="kagent-controller-metrics"` in the OTel stack.

Expand Down Expand Up @@ -143,12 +152,10 @@ Run the following queries in Prometheus or Grafana.
sum by (controller) (rate(controller_runtime_reconcile_errors_total{job="kagent-controller-metrics"}[5m]))
```

{{% version exclude-if="1.0.x,0.x" %}}
- Timer-driven session quiescence discoveries in the last hour.
```text
increase(kagent_session_quiescence_claimed_total{kagent_worker_trigger="recovery"}[1h])
```
{{% /version %}}

- The 95th percentile agent invocation duration, per Agent. Because both stack guides configure the collector to derive the metric, the query covers every runtime that opens an `invoke_agent` span.
```text
Expand Down
Loading