# Monitor an instance

Source: https://dropshelf.ai/docs/self-host/operate/monitor

Scrape a dropshelf instance's metrics, alert on the ones that matter, read its probes and logs, and search its event log.

This page is for operators who watch a dropshelf instance in production. It covers the metrics, the
health probes, the logs and the event log, which records every change.

## Prerequisites [#prerequisites]

- A Prometheus that discovers pods, or prometheus-operator.
- `kubectl` access to the `dropshelf` namespace, and `jq` to search the event log.

## Scrape the metrics [#scrape-the-metrics]

Every pod serves `/metrics` on port 9090, set by
[`server.metricsListen`](/docs/reference/configuration#server). It is never on the main port 8080,
so the Ingress cannot reach it. Choose the way your Prometheus finds targets:

- **A Prometheus that discovers pods:** nothing to set. The chart gives every pod the
  `prometheus.io/scrape`, `prometheus.io/port` and `prometheus.io/path` annotations.
- **prometheus-operator:** turn on the chart's ServiceMonitor, which also adds a metrics port to the
  Service.

To turn on the ServiceMonitor, add this to your values file and run `helm upgrade`:

```yaml
metrics:
  serviceMonitor:
    enabled: true
    labels:
      release: prometheus
```

Replace `release: prometheus` with the label your Prometheus selects ServiceMonitors on. Prometheus
scrapes every 30 seconds unless you set `metrics.serviceMonitor.interval`.

To check a pod's metrics by hand, forward the port and read one series:

```bash
kubectl -n dropshelf port-forward deploy/dropshelf 9090:9090
curl -s http://127.0.0.1:9090/metrics | grep dropshelf_build_info
```

The output is similar to:

```text
dropshelf_build_info{commit="3f9c2e1a",version="v0.5.0"} 1
```

## Metrics reference [#metrics-reference]

Every metric name starts with `dropshelf_`. The metrics worth knowing are these:

| Metric | Labels | What it tells you |
| --- | --- | --- |
| `dropshelf_http_requests_total` | `host_class`, `method`, `code` | Requests by host class: `control` for the dashboard and API, `drop` for drops. Split on it first in any incident. |
| `dropshelf_http_request_duration_seconds` | `host_class`, `route` | Latency. `route` is the route pattern on the control plane, and a fixed value such as `drop` on drop hosts. |
| `dropshelf_deploys_total` | `status`, `source` | Deploys by outcome. `source` is `web` for a session, `api` for a token and `mcp` for an agent. |
| `dropshelf_deploy_duration_seconds` | | How long a deploy takes. |
| `dropshelf_deploys_in_flight` | | Deploys running on this replica. At `deploy.maxConcurrentDeploys`, new deploys get 503. |
| `dropshelf_drops_live` | `type` | Live drops by type, written once per reaper run. |
| `dropshelf_reaper_processed_total` | `step` | What the reaper did, per step, such as `expire`, `purge` and `janitor_failed`. |
| `dropshelf_reaper_errors_total` | | One increment per failing reaper step per run. |
| `dropshelf_reaper_last_run_timestamp` | | Unix time of the reaper's last run. |
| `dropshelf_cache_hits_total`, `dropshelf_cache_misses_total` | `cache` | Hits and misses of the `object` cache on disk and the `manifest` cache in memory. |
| `dropshelf_cache_bytes`, `dropshelf_cache_objects` | `cache` | What each cache holds. For `object`, the bytes indexed under `cache.dir`. |
| `dropshelf_cache_errors_total` | `cache`, `op` | Cache failures, with `op` set to `fill`, `open` or `evict`. |
| `dropshelf_blob_ops_total`, `dropshelf_blob_op_errors_total` | `op` | Calls to the object store, and the ones that failed. |
| `dropshelf_blob_op_duration_seconds` | `op` | How long object store calls take. |
| `dropshelf_connector_runs_total` | `source`, `result` | Queries run against a connector source, a database or an MCP server, with `result` set to `ok`, `timeout`, `too_large`, `busy` or `error`. |
| `dropshelf_connector_runs_in_flight` | `source` | Queries running now. At the source's `maxConcurrent`, visitors get 503. |
| `dropshelf_build_info` | `version`, `commit` | Which release is answering. |

A hit ratio that drops after a deploy is normal: a new version is a new set of files to cache.

## Alert on what matters [#alert-on-what-matters]

These conditions are worth an alert:

- **The reaper stopped:** `dropshelf_reaper_last_run_timestamp` is older than a few runs. It runs
  every minute by default, set by [`reaper.interval`](/docs/reference/configuration#reaper).
- **The reaper is failing:** `dropshelf_reaper_errors_total` rises over a window. Expired drops
  still stop serving on time, but their names are not freed and their files stay in the bucket.
- **The object cache is failing:** `dropshelf_cache_errors_total` rises over a window. Repeated
  failures send misses to the bucket.
- **Deploys are saturated:** `dropshelf_deploys_in_flight` stays at `deploy.maxConcurrentDeploys`
  for longer than a deploy takes.
- **The control plane is failing:** the rate of 5xx answers with `host_class="control"`.

As Prometheus rules, those conditions look like this, at the default settings:

```yaml
- alert: DropshelfReaperStopped
  expr: time() - dropshelf_reaper_last_run_timestamp > 300
- alert: DropshelfReaperErrors
  expr: increase(dropshelf_reaper_errors_total[15m]) > 0
- alert: DropshelfObjectCacheErrors
  expr: increase(dropshelf_cache_errors_total{cache="object"}[15m]) > 0
- alert: DropshelfDeploysSaturated
  expr: dropshelf_deploys_in_flight >= 4
  for: 5m
- alert: DropshelfControlErrors
  expr: sum(rate(dropshelf_http_requests_total{host_class="control",code=~"5.."}[5m])) > 0.1
```

A flat `dropshelf_drops_live` can mean a quiet instance or a stopped reaper. Check that
`dropshelf_reaper_last_run_timestamp` advances before you trust it.

## Read the probes [#read-the-probes]

Every pod answers two probes on port 8080, for any host name:

| Path | Answers | Used for |
| --- | --- | --- |
| `/healthz` | `200` with `ok` while the process runs. | The liveness probe. |
| `/readyz` | `200` with `ready`, or `503` with `not ready:` and the first dependency that failed. | The readiness probe, and the first thing to read when requests fail. |

`/readyz` checks the database, the object store and the spool directory, in that order. It caches
its answer for five seconds, so a busy load balancer cannot turn it into load.
[Troubleshoot an instance](/docs/self-host/operate/troubleshooting) explains each `not ready` answer.

## Read the logs [#read-the-logs]

The server logs to standard error. Two settings shape it, under
[`log`](/docs/reference/configuration#log):

- `log.format`: `json`, the default, or `text` for `key=value` lines.
- `log.level`: `debug`, `info`, the default, `warn` or `error`.

At startup, the server logs `effective configuration` with every setting, secrets redacted.

The server does not log requests. A request that fails with 500 can leave no line at all, so read
`/readyz` before you search the log.

## Search the event log [#search-the-event-log]

Every change writes one log line with the message `event` at level info. This covers changes from
the dashboard, the API, the agents, the operator toolbox and the reaper. The log store you ship logs
to is the history, and it keeps what its retention keeps.

<Callout type="warn">
`log.level: warn` or `error` drops event lines with the rest of info. Keep `info` or `debug` on an
instance that needs the history.
</Callout>

An event line holds these fields. A field with nothing to say is left off:

| Field | What it holds |
| --- | --- |
| `event` | The event name, such as `drop.delete`, `drop.publish`, `user.disable` or `token.revoke`. |
| `actor_kind` | `user` for a member, `operator` for the toolbox, `system` for the reaper. |
| `actor` | The member's user id. |
| `source` | `web` for a session, `api` for a token, `mcp` for an agent, `cli` for the toolbox, `reaper` for the reaper. |
| `target_kind` | What changed, such as `drop`, `user`, `token` or `comment`. |
| `target` | The drop's name, the user id, the token id, or the comment id. |
| `request_id`, `ip`, `ua` | The request's id, address and `User-Agent`, on changes made over HTTP. |
| `details` | More about the change, such as `from` and `to` on a rename. A toolbox write adds `host`, the pod's name. |

The line also carries `time`, `level` and `msg`, like every log line. Query on `msg` and the fields
above.

To search, define a small shell function over `kubectl logs` and `jq`:

```bash
events() { # events <since> <jq condition>
  kubectl -n dropshelf logs -l app.kubernetes.io/name=dropshelf --since="$1" --tail=-1 \
    | jq -cR "fromjson? | select(.msg == \"event\" and ($2))"
}
```

`--tail=-1` matters, because `kubectl logs` with a label prints only ten lines per pod otherwise.

To find who deleted the drop `lunch-votes`, or whether it expired, in the last 30 days:

```bash
events 720h '.target == "lunch-votes" and (.event | IN("drop.delete", "admin.force_delete", "drop.expire"))'
```

To list every toolbox write from inside the cluster in the last week:

```bash
events 168h '.actor_kind == "operator"'
```

`kubectl logs` reaches only what the pods still hold. For older lines, run the same filters in the
store your logs are shipped to. With `log.format: text`, `grep` on the same fields does the job.

## Next steps [#next-steps]

- [Troubleshoot an instance](/docs/self-host/operate/troubleshooting)
- [Upgrade dropshelf](/docs/self-host/operate/upgrade)
- [Helm chart values](/docs/reference/helm-values#metrics)
- [Configuration reference](/docs/reference/configuration#log)
