Skip to content

Monitoring ​

Reminders, sync links and backups run in the background, where a failure shows no error page. GET /metrics exposes them in the Prometheus format, and GET /healthz is a liveness check. Every request is also logged as one JSON line with a correlation id.

Turning it on ​

/metrics is off by default. The numbers reveal how the instance is used (how many accounts, how busy it is, when people are active), so you choose who can read them. There are two ways to do that, and you can use both.

A bearer token on the main port ​

sh
METRICS_TOKEN=$(openssl rand -hex 32)

/metrics then answers on the normal port, and only to requests carrying Authorization: Bearer <token>. Without the variable the route answers 404; with it but without the right header, 401. Use this when Prometheus reaches HyperCloud through your reverse proxy or from another host.

A separate listener with no token ​

sh
METRICS_LISTEN=127.0.0.1:9464

This opens a second port that serves only /metrics, with no authentication. Its address is what keeps it private, so by default it must bind a loopback address (127.0.0.1, ::1, localhost), and the server refuses to start otherwise. This suits a Prometheus or agent running on the same machine.

In Docker, loopback inside the container is unreachable from a Prometheus container next to it. If the port is on a network only Prometheus can reach, say so explicitly:

yaml
environment:
  METRICS_LISTEN: 0.0.0.0:9464
  METRICS_LISTEN_ALLOW_PUBLIC: "1"
# and do not publish 9464 under `ports:`

The server logs a warning on every boot with that combination.

Scraping ​

yaml
# prometheus.yml
scrape_configs:
  - job_name: hypercloud
    scrape_interval: 15s
    scheme: https
    authorization:
      type: Bearer
      credentials_file: /etc/prometheus/hypercloud-token
    static_configs:
      - targets: ["calendar.example.com"]

For the separate listener, drop scheme and authorization and target 127.0.0.1:9464 (or the container's name and port).

Health check ​

GET /healthz needs no authentication. It answers 200 ok when the database responds, and 503 when it does not. The Docker image's HEALTHCHECK uses it, and it works as a Kubernetes liveness probe:

yaml
livenessProbe:
  httpGet: { path: /healthz, port: 3001 }
  periodSeconds: 30

What is exported ​

Every metric is prefixed hypercloud_, except the standard process_* ones, which use the names stock dashboards expect.

Reminders ​

MetricTypeLabels
hypercloud_reminder_scheduler_lag_secondshistogram
hypercloud_reminder_scheduler_last_tick_timestamp_secondsgauge
hypercloud_reminder_scheduler_tick_failures_totalcounter
hypercloud_reminders_sent_totalcounterchannel, status

Lag is the time between a reminder's scheduled instant and when it was actually sent. The scheduler wakes every 30 seconds, so anything up to 30 seconds is normal.

The last-tick timestamp is the one to alert on. A stalled scheduler sends nothing, and a reminder that is never sent records no lag at all. Neither metric exists when Web Push (VAPID_*) is not configured, since there is then no scheduler.

reminders_sent_total counts one delivery per device. Its status label is ok, error (the push service refused), or gone (the device unsubscribed and was removed, which is normal). channel is webpush.

Sync ​

MetricTypeLabels
hypercloud_dav_sync_runs_totalcounterkind, result
hypercloud_dav_requests_totalcounterkind, method, status
hypercloud_subscription_fetches_totalcounterresult
hypercloud_sync_linksgaugekind, state
hypercloud_sync_oldest_success_timestamp_secondsgaugekind

The label values are:

  • kind: caldav, carddav (address books) or ics (subscriptions).
  • result: ok or error. ICS fetches can also be not_modified.
  • state: ok or failing. failing means the last sync ended in an error.
  • status: a status class (2xx, 4xx, …), or error when no response arrived at all (DNS failure, timeout, refused address).

oldest_success is the least recent successful sync across all links of that kind. A link that has never succeeded counts from when it was created. When nothing of a kind is linked, the series is absent.

Backups ​

MetricTypeLabels
hypercloud_backup_last_success_timestamp_secondsgaugekind
hypercloud_backup_last_duration_secondsgaugekind
hypercloud_backup_failures_totalcounterkind

kind is database (the daily VACUUM INTO snapshot) or accounts (the backups into each account's Files, and the daily per-user .hypercalendar files of accounts without Files). For accounts the success is the last hourly pass in which no account's backup failed, so it stays fresh while accounts back up weekly. The backups keep their outcomes in the database and these are read from there, so the failures count does not restart with the server.

Audit log ​

MetricTypeLabels
hypercloud_audit_events_totalcounter
hypercloud_audit_dropped_totalcounter
hypercloud_audit_pruned_totalcounter

HTTP ​

MetricTypeLabels
hypercloud_http_requests_totalcounterroute, method, status
hypercloud_http_request_duration_secondshistogramroute, method

Load ​

MetricTypeLabels
hypercloud_memory_budget_bytesgaugestate (total, in_use)
hypercloud_memory_limit_bytesgauge
hypercloud_requests_refused_totalcounterreason (busy, memory, too_large, timeout)

The memory budget is what the work holding whole files in memory may hold at once. hypercloud_memory_limit_bytes is the container's memory limit, and is missing without one. A request is refused as busy past MAX_REQUESTS, as memory when its body found no room in the budget in time, as too_large when it never could, and as timeout past REQUEST_TIMEOUT.

Instance ​

MetricTypeLabels
hypercloud_db_size_bytesgauge
hypercloud_usersgauge
hypercloud_eventsgauge
hypercloud_build_infogaugeversion, node_version (empty)
process_resident_memory_bytesgauge
process_cpu_seconds_totalcounter
process_start_time_secondsgauge

hypercloud_db_size_bytes measures the main database file and excludes the WAL. hypercloud_events excludes the trash.

What labels never contain ​

Labels never carry a user, event, calendar or link. They never include a name, an id, a URL, or a token from a feed or poll link.

  • route is the pattern that answered (/api/events/:id), never the path. A request no route matched is labelled with the pattern of the middleware that answered it, or unmatched.
  • method collapses anything unexpected to other.

Dashboard and alerts ​

  • Grafana dashboard: import it in Grafana (Dashboards → New → Import) and pick your Prometheus data source. It has panels for health, reminders, sync, HTTP and the process.

  • Alert rules: load them with rule_files: [alerts.yml]. They cover:

    • a scheduler with no pass in 5 minutes;
    • reminder p95 lag over 2 minutes;
    • pushes failing;
    • links failing for 6 hours, or not synced in 3 days;
    • backups older than 26 hours, or failed;
    • more than 5% of requests answered with a 5xx;
    • memory over 90% of the container's limit;
    • requests being turned away under load;
    • the server restarting more than twice in an hour (killed for memory, mostly).

    The thresholds are starting points; tune them to your instance.