Files
wekan/docs/Features/Metrics.md
T
Lauri Ojansivu 7e1f9e89eb Docs: every feature topic in one folder under docs/Features, each with README.md as its main page.
- The General/ level is gone: its 109 files moved up into the folders of the
  same name, and its topic table is the "Shared topics" section of
  Features.md.
- Accessibility is one folder, docs/Features/Accessibility/, with the Admin
  Panel's accessibility page in it.
- Every folder's main page is README.md (110 X/X.md pages renamed with git mv,
  five merged with an existing README.md, 26 index pages added for folders
  that had none), so a folder opened on GitHub shows its page.
- The 73 "# Moved" forwarding pages are deleted, with the folders that held
  only them; every link that went to one goes to its final page.
- docs/Features/README.md has the website's "Features in WeKan" overview,
  each feature linking to its page here.

1,129 Markdown links in 262 files and 352 doc paths in code, tests, compose,
snap and release files follow. tests/docsFeaturesLayout.test.cjs fails when
General/ or a "# Moved" page comes back, a folder has no README.md, or a
relative link in the docs or README.md does not resolve.

Thanks to xet7 !
2026-11-24 20:02:06 +02:00

8.7 KiB

Metrics

What it is

WeKan can be watched from outside in two ways. Metrics is an HTTP endpoint, /metrics, that answers in the plain-text Prometheus format with counts such as connected users, registered boards and the health of the instance backup, so a monitoring system can graph them and alert on them. Matomo is optional web analytics: when it is configured, every page view in WeKan is reported to your own Matomo server.

Read more

How to use it

Allow a scraper to read /metrics. The endpoint answers only a request from an allowed address or one carrying the access token.

  1. Choose how the scraper proves it may read the numbers:
    • by address: set METRICS_ACCEPTED_IP_ADDRESS to a comma-separated list, for example METRICS_ACCEPTED_IP_ADDRESS=192.168.0.100,192.168.0.200;
    • by token: set METRICS_ACCESS_TOKEN to a long random string, and send it as Authorization: Bearer <token> or as ?access_token=<token>.
  2. If WeKan is behind a reverse proxy and you allow by address, set METRICS_TRUST_PROXY to the number of trusted proxy hops (for example 1); otherwise the address WeKan sees is the proxy's own.
  3. Restart WeKan.
  4. Point Prometheus at https://<your-wekan>/metrics. A refused request gets HTTP 401 and a line that names the address WeKan saw; behind a proxy it also says what to set.

The example settings in docker-compose.yml, start-wekan.sh, the Dockerfile and the Snap (metrics-allowed-ip-addresses) are named METRICS_ALLOWED_IP_ADDRESSES:

- METRICS_ALLOWED_IP_ADDRESSES=192.168.0.100,192.168.0.200

See docker-compose.yml. Note that the code that serves /metrics reads METRICS_ACCEPTED_IP_ADDRESS (see below), so set that name.

Alert on a missing backup. Add a Prometheus rule such as time() - wekan_backup_last_success_timestamp_seconds > 26*3600.

Matomo. Set MATOMO_ADDRESS (the Matomo server URL, ending in /), MATOMO_SITE_ID, and optionally MATOMO_DO_NOT_TRACK and MATOMO_WITH_USERNAME. With MATOMO_WITH_USERNAME the WeKan username is sent to Matomo as the user id.

How the numbers are calculated

All in models/server/metrics.js, computed fresh on every request:

Metric How it is computed
wekan_connectedUsers open DDP sockets whose session has a user id (one user with two tabs counts twice)
wekan_registeredUsers number of documents in users
wekan_registeredboards boards with archived: false and type: 'board' (templates are not counted)
wekan_registeredboardsBysRegisteredUsers wekan_registeredboards / wekan_registeredUsers, a plain division, not rounded
wekan_registeredboardsWithOnlyOneMember unarchived boards whose members array has exactly one entry
wekan_usersWithLastConnectionDated5DaysAgo (and 10, 20, 30) users whose lastConnectionDate is within the last 5, 10, 20 or 30 days (now - days * 24 * 60 * 60 * 1000); each count includes the shorter ones
wekan_top10BoardsWithMostActivities{n="<title>"} activities with modifiedAt in the last 30 days, grouped by boardId, sorted by count, highest first; the value is the rank 1, 2, .... The limit passed is the 30 of the day window, so up to 30 boards are listed despite the name
wekan_backup_last_success_timestamp_seconds Unix time of the last successful instance backup, 0 = never
wekan_backup_last_run_timestamp_seconds Unix time the last instance backup run ended (or started, while running)
wekan_backup_last_run_success 1 when the backup state is ok or overdue, else 0
wekan_backup_overdue 1 when a scheduled backup has not succeeded within its period plus a two-hour grace: 1 day, 7 days or 31 days for daily, weekly and monthly schedules

The backup lines come from backupMetricsLines() and backupHealth() in models/lib/backupRuns.js; organization backups do not count. If reading the backup history fails, the endpoint writes # backup metrics unavailable and still returns the other metrics.

How it works in WeKan

  • models/server/metrics.js registers WebApp.handlers.use('/metrics', ...) at startup.
  • Access: acceptedIpAddress() compares the client address with the comma-separated METRICS_ACCEPTED_IP_ADDRESS; accessToken() reads a Bearer header or access_token query parameter and compares SHA-256 digests of it and METRICS_ACCESS_TOKEN with crypto.timingSafeEqual. An unset or empty token never matches.
  • The client address is the socket peer. X-Forwarded-For is used only when METRICS_TRUST_PROXY is set, and then the entry that many hops from the right of the chain, which a client cannot forge (the MetricsBleed fix reported by meifukun).
  • A refused request that carries X-Forwarded-For naming an allowed address, while the real connection is not from one, trips the spoof.forwarded-header canary (server/lib/canary), which shows in Admin Panel → Problems. An ordinary proxy header is not logged.
  • Matomo: client/lib/utils.js manageMatomo(), called by the routes in config/router.js, subscribes to matomoConfig (server/publications/customUI.js), and when the settings document has matomoURL and matomoSiteId, setMatomo() loads <address>piwik.js and pushes trackPageView. The environment variables are read by getMatomoConf() in server/models/settings.js; in the current code that function has no caller and nothing writes matomoURL into the settings document, so Matomo tracking may not start from the environment variables alone.
  • Tests: tests/metricsAccessToken.test.cjs, tests/securityMeifukun.test.cjs, tests/restartIsNotACrash.test.cjs and the Matomo case in client/lib/tests/Utils.tests.js.

Commits