---
title: Monitoring
description: Watch a self-hosted Peal from outside, and export its logs, metrics and traces over OTLP.
sidebar:
  icon: activity
---

Grafana's alerts run on the server they watch, so they can't tell you when that server is down. A second machine can. You can also send the server's telemetry to any OpenTelemetry collector.

## Watch it from outside [#uptime]

When the server, its network or Grafana stops, Grafana's alerts stop too. Watch the instance from another machine as well, one that shares nothing with it and sends alerts its own way.

Check what people reach, through your edge:

| Check                                   | Passes when                                                        |
| --------------------------------------- | ------------------------------------------------------------------ |
| `GET /api/ready`                        | It answers `204 No Content`, so the server and its database answer |
| A page of the web app, such as `/login` | It answers `200`                                                   |
| The certificate                         | It has time left                                                   |

Count a redirect as a failure, so a sign-in page in front of the instance never passes for it.

### Set up Grafana's heartbeat [#heartbeat]

Grafana can show that its own alerting works. With these settings, a rule that always fires posts to `PEAL_HEARTBEAT_URL` about every 5 minutes, with the token as a bearer token:

| Setting                  | Value                                                 |
| ------------------------ | ----------------------------------------------------- |
| `PEAL_GRAFANA_HEARTBEAT` | `./config/production/grafana/alerting/heartbeat.yaml` |
| `PEAL_HEARTBEAT_URL`     | The checker's push address                            |
| `PEAL_HEARTBEAT_TOKEN`   | The checker's token                                   |

If the posts stop, Grafana, Prometheus or the way out is down, and the other alerts may not reach you either. The checker tells you.

With [Gatus](https://github.com/TwiN/gatus), make the heartbeat an external endpoint with a heartbeat interval of 15 minutes. Set `PEAL_HEARTBEAT_URL` to its push address, `https://<gatus>/api/v1/endpoints/<group>_<name>/external?success=true`. [Environment variables](/self-hosting/environment-variables#compose) lists these settings.

Peal's own servers are watched this way. [Deployment](https://github.com/peal-social/peal/blob/main/packages/peal-infra/DEPLOYMENT.md#uptime) describes the uptime server, and its Ansible and Gatus configuration are in `packages/peal-infra/ansible`.

## Export telemetry [#telemetry]

Set `OTEL_EXPORTER_OTLP_ENDPOINT` to an OpenTelemetry collector's OTLP/HTTP address, such as `http://otel-collector:4318`. The server then exports its logs, metrics and traces there, as JSON. [Environment variables](/self-hosting/environment-variables#telemetry) lists the other OpenTelemetry settings it reads.

### Web app errors [#web-errors]

The web app reports its errors to the server, at `POST /api/client-errors`. It reports four kinds:

- Errors nothing caught in a browser.
- Promises rejected without a handler.
- The error pages its boundaries show.
- Pages its own server failed to render.

A browser sends each error once, and ten at most per page.

A report names nobody, and it sends no cookie. It holds the error's message and stack, the page's route, the release and the browser's user agent. It also holds the page's path, without its query or fragment and with its ids replaced. The server replaces any email address, id, API key, token or link's query the report still quotes, and drops control characters.

The server takes 30 reports a minute from each address, which it reads from the header `AUTH_IP_HEADERS` names, and 16 KiB at most per report. It logs each one at error level, with the event name `peal.client_error` and OpenTelemetry's attribute names: `exception.message`, `exception.stacktrace`, `url.path`, `http.route`, `user_agent.original`, plus `peal.client_error.kind` and `peal.web.release`.

You'll find them here:

| Where      | What                                                                                                            |
| ---------- | --------------------------------------------------------------------------------------------------------------- |
| Metrics    | `peal.client_errors`, by kind. The reports it drops are in `peal.client_errors.dropped`, by reason.             |
| Prometheus | `peal_client_errors_total` and `peal_client_errors_dropped_total`                                               |
| Loki       | `{service_name="peal-server"} \| event_name="peal.client_error"`                                                |
| Grafana    | The production stack's **Web app errors** dashboard, which warns when more than 20 reports arrive in 10 minutes |

The alert on the server's own error logs leaves these reports out. To name the release the reports come from, set `PEAL_RELEASE` on the web app. The production stack sets it to `PEAL_VERSION`.

### Meta's refusals [#meta-refusals]

When Meta refuses a call to Facebook, Instagram or Threads, the server counts it in `peal.meta.refusals` (Prometheus: `peal_meta_refusals_total`). Each count says which API answered (`facebook`, `instagram`, `threads`), the kind of refusal and Meta's code, such as `graph10`. The kinds are `token`, `permission`, `rateLimited`, `unavailable`, `duplicate` and `refused`. Meta's message is never kept.

The span of each refusal holds the same fields, plus `meta.error.type` and `meta.error.trace_id`, the id Meta's support asks for. A refused token is also logged as a warning, "Meta refused a token".

`permission` means the app lacks a permission the call needs, or the account didn't grant it. A new token doesn't help: the post fails with Meta's code and the channel stays connected. The production stack's `peal-meta-permission-refused` alert fires on the first one. Add the permission to your Meta app's use case, or stop sending the option that needs it.

### Channels to reconnect [#reconnects]

Each channel marked to reconnect is counted once in `peal.channels.reconnect_required` (Prometheus: `peal_channels_reconnect_required_total`), by platform and cause:

| Cause            | What happened                                          |
| ---------------- | ------------------------------------------------------ |
| `tokenRefused`   | The platform refused the token when it was used, twice |
| `renewalRefused` | The token sweep could not renew the token              |
| `expired`        | The token expired and couldn't be renewed              |
| `deauthorized`   | The account removed the app on the platform            |

Accounts rarely need reconnecting all at once. The production stack's `peal-channels-reconnect-wave` alert fires when more than four channels of one platform are marked within an hour, removals left out. It usually means a revoked app, a permission taken away or a changed secret, so check the platform's developer console before telling the workspaces.

### Publishing outcomes [#publishing-outcomes]

Each channel of a post is counted once its round settles, in `peal.publishing.outcomes` (Prometheus: `peal_publishing_outcomes_total`). Each count has the platform, the outcome (`published`, `failed` or `unconfirmed`) and the reason: why it failed or wasn't confirmed, or `none` when it was published. A settlement the server retries after a database failure counts again.

The production stack's `peal-publishing-failing` alert fires when more than five posts failed on one platform in an hour and those are over half of what settled there. The reason label usually says which: a permission the app lost, a platform change or a broken adapter.

### Platform answers [#outbound-responses]

The server counts every request it sends to a platform in `peal.outbound.responses` (Prometheus: `peal_outbound_responses_total`), and a retry counts again. Each count has two labels:

| Label     | Values                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `service` | The platform the host belongs to: `meta` (Facebook and Instagram), `threads`, `tiktok`, `x`, `linkedin`, `youtube`, `googleAds`, `googleBusiness` (Business Profile), `google` (Google's sign-in and its other APIs), `pinterest`, `snapchat`, `bluesky`, `devto`, `hashnode`, `wordpress` (WordPress.com), `slack`, `discord`, `telegram`, `anthropic` or `openai`. Any other host counts as `other`, such as a Mastodon instance, a WordPress site, a webhook, a feed or your own AI endpoint, so the label never holds a host name or an address. |
| `status`  | `2xx`, `3xx`, `4xx`, `429` (apart from the other 4xx), `5xx`, or `failed` when no answer came: a timeout, a lost connection or a request the server refused to send.                                                                                                                                                                                                                                                                                                                                                                                 |

The production stack's `peal-outbound-failing` alert fires for a service when 429s, 5xx and requests that got no answer (`failed`) are more than a quarter of its requests over 30 minutes, out of 50 requests or more. Each service alerts on its own, and the alert names it. A 429 means Peal hit the platform's rate limit, and a 5xx or a request left unanswered is usually an outage on the platform's side, so check its status page first. Hosts counted as `other` never alert: your members chose them, and one of them failing says nothing about a platform.
