# Monitoring and signals

`almad` exposes health and metrics endpoints on two configurable listeners:

* `/healthz` and `/readyz` - liveness and readiness, on the address `ALMA_DIAG_LISTEN` binds. It has no default, so the endpoint is off until you set one. This page uses `:3000` throughout.
* `/metrics` - Prometheus exposition format, on the address `ALMA_METRICS_LISTEN` binds. An address given without a port gets `:3081`. While the variable is unset, the diagnostic listener serves `/metrics` itself, so binding only `ALMA_DIAG_LISTEN` still exposes metrics.

The diagnostic port is what your load balancer health-checks. The metrics port is what Prometheus scrapes. Both should stay on private networks.

`almad` can also push metrics, logs and traces to an OpenTelemetry Collector instead of, or as well as, being scraped. See [OpenTelemetry export](#opentelemetry-export).

## Scrape configuration[​](#scrape-configuration "Direct link to Scrape configuration")

Enable both endpoints in `/etc/almaforge/almad.env`:

/etc/almaforge/almad.env

```env
ALMA_DIAG_LISTEN=0.0.0.0:3000

ALMA_METRICS_LISTEN=0.0.0.0:3081
```

The metrics listener serves mutual TLS or plaintext, with nothing in between. To require a certificate from the scraper, set all three of these next to `ALMA_METRICS_LISTEN`:

env

```env
ALMA_METRICS_TLS_CERT=/etc/almaforge/metrics.crt

ALMA_METRICS_TLS_KEY=/etc/almaforge/metrics.key

ALMA_METRICS_CLIENT_CA=/etc/almaforge/scraper-ca.crt
```

Setting only some of them fails at startup rather than quietly serving plaintext. Prometheus then needs a `tls_config` presenting a certificate that `ALMA_METRICS_CLIENT_CA` issued. Full descriptions are in the [environment reference](https://almaforge.com/reference/environment.md#listen-and-advertise-addresses).

Add each `almad` metrics listener to your Prometheus targets:

[`prometheus-static.yaml`](https://almaforge.com/examples/monitoring/prometheus-static.yaml):

examples/monitoring/prometheus-static.yaml

```yaml
# Static Prometheus scrape targets for the almad metrics endpoint.

# Use hostnames reachable from your Prometheus server.

- job_name: almad

  static_configs:

    - targets:

        - 'almaforge-1.internal:3081'

        - 'almaforge-2.internal:3081'

        - 'almaforge-3.internal:3081'
```

On Kubernetes, enable `integrations.prometheus.serviceMonitor.enabled: true` in the cluster or agent [Helm chart](https://almaforge.com/deployment/kubernetes.md#prometheus-operator) to create a `ServiceMonitor` for the Prometheus operator.

For the full metric catalog, see the [Metrics Reference](https://almaforge.com/reference/metrics.md).

## OpenTelemetry export[​](#opentelemetry-export "Direct link to OpenTelemetry export")

`almad` exports metrics, logs and traces over OTLP to an OpenTelemetry Collector, or to any backend that accepts OTLP directly. It is configured with the standard OpenTelemetry environment variables, the same ones every OpenTelemetry SDK reads, so a collector's own documentation applies unchanged.

Nothing is exported until you name an endpoint. Point every signal at one collector:

/etc/almaforge/almad.env

```env
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318
```

`almad` appends `/v1/metrics`, `/v1/logs` and `/v1/traces` to that base URL. To use gRPC instead of OTLP/HTTP, add `OTEL_EXPORTER_OTLP_PROTOCOL=grpc` and point at the gRPC port, usually `4317`. Use `https://` whenever the collector sits across a network you do not trust.

### Send each signal to its own backend[​](#send-each-signal-to-its-own-backend "Direct link to Send each signal to its own backend")

Each signal can have its own endpoint, protocol, headers and certificates. A signal endpoint is used exactly as written, path included, and only that signal turns on:

/etc/almaforge/almad.env

```env
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://tempo.example.com/v1/traces

OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=https://mimir.example.com/otlp/v1/metrics

OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://loki.example.com/otlp/v1/logs

OTEL_EXPORTER_OTLP_LOGS_HEADERS=authorization=Bearer <token>
```

To switch one signal off while the shared endpoint stays set, use `OTEL_TRACES_EXPORTER=none`, `OTEL_METRICS_EXPORTER=none` or `OTEL_LOGS_EXPORTER=none`. Each signal goes to one destination. To send a signal to two backends, or to filter it on the way, point `almad` at a collector and route it there.

### Supported variables[​](#supported-variables "Direct link to Supported variables")

| Variable                                                                                  | Default                                         | What it controls                                                                             |
| ----------------------------------------------------------------------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `OTEL_EXPORTER_OTLP_ENDPOINT`                                                             | none                                            | Base URL for every signal. Setting it turns export on.                                       |
| `OTEL_EXPORTER_OTLP_<SIGNAL>_ENDPOINT`                                                    | none                                            | Full URL for one signal, used as written. Setting it turns that signal on.                   |
| `OTEL_EXPORTER_OTLP_[<SIGNAL>_]PROTOCOL`                                                  | `http/protobuf`                                 | `http/protobuf` or `grpc`.                                                                   |
| `OTEL_<SIGNAL>_EXPORTER`                                                                  | `otlp`                                          | `otlp` or `none`.                                                                            |
| `OTEL_EXPORTER_OTLP_[<SIGNAL>_]HEADERS`                                                   | none                                            | Request headers, as `key=value` pairs separated by commas, for collector authentication.     |
| `OTEL_EXPORTER_OTLP_[<SIGNAL>_]CERTIFICATE`                                               | system CA store                                 | CA bundle that verifies an `https://` collector.                                             |
| `OTEL_EXPORTER_OTLP_[<SIGNAL>_]CLIENT_CERTIFICATE`, `..._CLIENT_KEY`                      | none                                            | Client certificate for a collector that requires mutual TLS.                                 |
| `OTEL_EXPORTER_OTLP_[<SIGNAL>_]COMPRESSION`                                               | none                                            | `gzip` to compress exports.                                                                  |
| `OTEL_EXPORTER_OTLP_[<SIGNAL>_]TIMEOUT`                                                   | `10000`                                         | Export timeout in milliseconds.                                                              |
| `OTEL_METRIC_EXPORT_INTERVAL`                                                             | `60000`                                         | Milliseconds between metric pushes.                                                          |
| `OTEL_BLRP_MAX_QUEUE_SIZE`, `OTEL_BLRP_MAX_EXPORT_BATCH_SIZE`, `OTEL_BLRP_SCHEDULE_DELAY` | `2048`, `512`, `1000`                           | Log record queue size, batch size and milliseconds between batches.                          |
| `OTEL_BSP_MAX_QUEUE_SIZE`, `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`, `OTEL_BSP_SCHEDULE_DELAY`    | `2048`, `512`, `5000`                           | The same for spans.                                                                          |
| `OTEL_TRACES_SAMPLER`, `OTEL_TRACES_SAMPLER_ARG`                                          | `parentbased_always_on`                         | Which traces are recorded, for example `parentbased_traceidratio` with an argument of `0.1`. |
| `OTEL_SERVICE_NAME`, `OTEL_RESOURCE_ATTRIBUTES`                                           | see [Resource attributes](#resource-attributes) | Override or add resource attributes.                                                         |

`<SIGNAL>` is `TRACES`, `METRICS` or `LOGS`, and a signal variable wins over its shared form. An endpoint that is not an `http://` or `https://` URL, an exporter other than `otlp` or `none`, and a protocol other than the two listed all stop `almad` at startup, rather than sending to the wrong place.

### Metrics[​](#metrics "Direct link to Metrics")

Every 60 seconds, or as often as `OTEL_METRIC_EXPORT_INTERVAL` says, `almad` pushes the metrics that `/metrics` serves, with the same names and labels. Dashboards and alerts written against a Prometheus scrape work on the pushed data without changes. A counter arrives as a monotonic sum, and a gauge and a histogram keep their types.

The push is independent of `ALMA_METRICS_LISTEN`. You can push only, scrape only, or do both.

### Logs[​](#logs "Direct link to Logs")

Every record at `ALMA_LOG_LEVEL` or above is exported. It is also still written to `ALMA_LOG_OUTPUT` as before, so `journalctl` keeps working. The message becomes the record body, the level becomes the severity, and fields keep their names, except for the ones in this table, which take their OpenTelemetry names:

| Local log field                  | OTLP attribute                                                                 |
| -------------------------------- | ------------------------------------------------------------------------------ |
| `component`                      | `alma.component`                                                               |
| `worker`                         | `alma.worker`                                                                  |
| `error`                          | `exception.message`                                                            |
| `stack`, on `ERROR` records only | `exception.stacktrace`                                                         |
| `caller`, at `debug` level only  | `code.file.path`, `code.line.number` and `code.function.name`, on every record |

Nested fields use dotted names, such as `request.addr`. Credentials are redacted from exported records the same way they are from the local log.

### Traces[​](#traces "Direct link to Traces")

`almad` exports the spans it records. By default every new trace is recorded. A request that arrives with its caller's sampling decision keeps that decision, so a trace is never cut off partway through `almad`. Set `OTEL_TRACES_SAMPLER` to record fewer.

### Resource attributes[​](#resource-attributes "Direct link to Resource attributes")

Every exported metric, log record and span identifies its source with standard OpenTelemetry resource attributes:

| Attribute         | Value                                                               |
| ----------------- | ------------------------------------------------------------------- |
| `service.name`    | `almad`                                                             |
| `service.version` | The `almad` version                                                 |
| `host.name`       | The node name, `ALMA_NODE_NAME` when set, otherwise the OS hostname |
| `host.id`         | The machine ID, when the host has one                               |
| `host.arch`       | `amd64` or `arm64`                                                  |
| `os.type`         | `linux` or `darwin`                                                 |
| `process.pid`     | The `almad` process ID                                              |

`OTEL_SERVICE_NAME` and `OTEL_RESOURCE_ATTRIBUTES` are applied last, so they can rename the service or add attributes such as `deployment.environment.name=prod`. Spans also carry `alma.version`, `alma.host.name`, `alma.host.uuid` and `alma.process.id`.

### When the collector is down[​](#when-the-collector-is-down "Direct link to When the collector is down")

A failed export is logged as a warning with `component=otel` in the local log only, never exported itself, and `almad` keeps running. Metrics are cumulative, so the next successful push carries the current totals and only the samples in between are lost. Log records are held in a bounded in-memory queue, so a long outage drops the oldest records rather than growing memory. Spans are queued the same way and dropped once their queue is full. The `OTEL_BLRP_*` and `OTEL_BSP_*` variables size those queues.

## Signals to watch[​](#signals-to-watch "Direct link to Signals to watch")

These are the metrics most likely to catch a problem before users do:

| Signal                               | Metric                                                     | What it means                                                              |
| ------------------------------------ | ---------------------------------------------------------- | -------------------------------------------------------------------------- |
| Storage backend write latency        | `backend_write_seconds` (p99)                              | State backend (etcd, PostgreSQL, DynamoDB, or Firestore) is the bottleneck |
| Host certificate generation pressure | `auth_generate_requests_throttled_total`                   | Auth is throttling host and service certificate generation                 |
| Audit emit failures                  | `audit_failed_emit_events`                                 | Audit event emission is failing. Investigations may have gaps              |
| Active SSH sessions                  | `proxy_ssh_sessions_total`                                 | Proxy load envelope                                                        |
| File-descriptor pressure             | `process_open_fds / process_max_fds`                       | Proxy or Auth is close to running out of sockets                           |
| Process CPU                          | `rate(process_cpu_seconds_total[5m])`                      | Sustained pressure means add replicas or bigger nodes                      |
| Recording upload latency             | `s3_requests_seconds`, `gcs_event_storage_uploads_seconds` | Session recordings backing up at the object store                          |

See the [Scaling Guide](https://almaforge.com/scaling.md) for the full breakdown of what each signal means and how to act on it.

## Alerts that earn their keep[​](#alerts-that-earn-their-keep "Direct link to Alerts that earn their keep")

Wire these as a starting set. Tune the thresholds for your shape:

* **`/readyz` returning non-200 for more than 30 seconds.** The process exists but is not serving. Page on-call.
* **`audit_failed_emit_events` rate above zero for more than 5 minutes.** Audit event delivery is failing. Page on-call, preserve daemon logs for the affected interval, and investigate missing records. Document any audit gap and report it under your audit policy.
* **`auth_generate_requests_throttled_total` rate sustained above zero.** Host and service certificate generation is being throttled. Check Auth load and state backend latency before resizing Auth.
* **`LockCreate` events** (from your audit sink, not Prometheus). Every lock is a security event worth a notification.
* **`process_open_fds / process_max_fds` above 0.7 for any replica.** Resize before the limit is hit.

For audit event codes and fields, see [Audit Events](https://almaforge.com/reference/audit.md).

## Where to look first[​](#where-to-look-first "Direct link to Where to look first")

When an alert fires:

1. Check `/readyz` on every replica. A non-200 response identifies process state, not the failed dependency.
2. Check `journalctl -u almad -n 200` on the affected host for the exact error.
3. Cross-reference with the [Troubleshooting](https://almaforge.com/troubleshooting.md) guide for the failing surface.
4. Check the state backend's own health (etcd member-list, Postgres primary status, DynamoDB throttling metrics).

## References[​](#references "Direct link to References")

* [Metrics Reference](https://almaforge.com/reference/metrics.md) - full Prometheus metric catalog.
* [Audit Reference](https://almaforge.com/reference/audit.md) - event codes and fields.
* [Scaling](https://almaforge.com/scaling.md) - how to act on each signal.
* [Troubleshooting](https://almaforge.com/troubleshooting.md) - symptom-to-cause index.
