- 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 !
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
- Prometheus (software) on
Wikipedia, and the
Prometheus text exposition format
that
/metricsanswers in. - Matomo (software) on Wikipedia, and matomo.org.
- Matomo settings keys for the Snap.
- Original metrics pull request. Thanks to Emile840.
- Related WeKan pages: Stats, Logs, Backup.
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.
- Choose how the scraper proves it may read the numbers:
- by address: set
METRICS_ACCEPTED_IP_ADDRESSto a comma-separated list, for exampleMETRICS_ACCEPTED_IP_ADDRESS=192.168.0.100,192.168.0.200; - by token: set
METRICS_ACCESS_TOKENto a long random string, and send it asAuthorization: Bearer <token>or as?access_token=<token>.
- by address: set
- If WeKan is behind a reverse proxy and you allow by address, set
METRICS_TRUST_PROXYto the number of trusted proxy hops (for example1); otherwise the address WeKan sees is the proxy's own. - Restart WeKan.
- 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-separatedMETRICS_ACCEPTED_IP_ADDRESS;accessToken()reads a Bearer header oraccess_tokenquery parameter and compares SHA-256 digests of it andMETRICS_ACCESS_TOKENwithcrypto.timingSafeEqual. An unset or empty token never matches. - The client address is the socket peer.
X-Forwarded-Foris used only whenMETRICS_TRUST_PROXYis 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-Fornaming an allowed address, while the real connection is not from one, trips thespoof.forwarded-headercanary (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 tomatomoConfig(server/publications/customUI.js), and when the settings document hasmatomoURLandmatomoSiteId,setMatomo()loads<address>piwik.jsand pushestrackPageView. The environment variables are read bygetMatomoConf()in server/models/settings.js; in the current code that function has no caller and nothing writesmatomoURLinto 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
- Backup health lines on /metrics
- Compare the access token in constant time and refuse an empty one
- A reverse proxy header alone is not logged as spoofing
- Canary for a forged forwarded-for header
- Security log for the metrics forwarded-for check
- Use the socket address unless METRICS_TRUST_PROXY is set
- Async ReactiveCache calls for Meteor 3
- Rename the allowlist variable to METRICS_ACCEPTED_IP_ADDRESS
- Example METRICS_ALLOWED_IP_ADDRESSES for Docker, Snap and source
- Fix the order of the top boards metric
- Fix quotes around the metric label
- Rename metric keys and add a new one
- Fix typos and translate comments to English
- More KPI metrics
- First KPI metrics