feat/fix: Revamp of usage tracking, endpoint and display
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
- [x] Target branch: Please verify that the pull request targets the
devbranch. - [x] Description: Provide a concise description of the changes made in this pull request.
- [x] Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
- [x] Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
- [x] Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
- [x] Testing: Have you written and run sufficient tests to validate the changes?
- [x] Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
- [x] Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
- BREAKING CHANGE: Significant changes that may affect compatibility
- build: Changes that affect the build system or external dependencies
- ci: Changes to our continuous integration processes or workflows
- chore: Refactor, cleanup, or other non-functional code changes
- docs: Documentation update or addition
- feat: Introduces a new feature or enhancement to the codebase
- fix: Bug fix or error correction
- i18n: Internationalization or localization changes
- perf: Performance improvement
- refactor: Code restructuring for better maintainability, readability, or scalability
- style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
- test: Adding missing tests or correcting existing tests
- WIP: Work in progress, a temporary label for incomplete or ongoing work
Changelog Entry
Description
Revamped tracking and display of "usage", fixing a tracking issue, exposing only necessary information to the client (i.e. not all active user IDs) and now displaying the actual concurrent LLM usage, overall and per model, which is arguably the more more interesting metric compared to the number of users with active websockets.
Added
- tracking of active chat completions count per model
- exposure of these metrics via /api/usage
- display of these metrics in UserMenu, both in the menu and the tooltip on hover
- locale string incl. German translation
Changed
- expose only active user count to the clients, not the full user list
- instead of a list of session ids, a list of message ids is tracked per model
Removed
- Unused websocket variables
activeUserIds,USAGE_POOL
Fixed
- make sure "usage" is emitted on socket at least once, such that USAGE_POOL is reliably filled
Security
- arguably, openly exposing the full user list on /api/usage without need isn't best practice, even if it's just IDs
Breaking Changes
- BREAKING CHANGE: /api/usage now yields only active user count, not the full list of IDs
- BREAKING CHANGE: /api/usage now yields a dict of active model names and their request counts, instead of just a list of active models
Additional Information
- In a further PR, the visibility of the whole display should be configurable, allowing for settings Everyone/Admins/Disabled
- In a further PR, cleanup mechanics for USER_POOL should be revisited
- This PR is 100% handcrafted, so please don't hurt my feelings 😅
Screenshots or Videos
Issue before this PR, where USAGE_POOL wasn't reliably filled -> no tooltip appears on hover:
https://github.com/user-attachments/assets/8a691796-abe5-4ed1-af2b-7a64ae7c80bd
With this PR, A) model usage is tracked properly and B) overall and individual running requests are displayed:
https://github.com/user-attachments/assets/63ef0f69-984e-4a4e-84bb-1853c1da8cd6
Also, just a proof that active users are tracked properly:
https://github.com/user-attachments/assets/e88f894f-bd19-47c8-93de-2affe296bc8a
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
This is cool, but is there a way to disable this? Not sure I want every user to know we have models running that are in a closed beta.
Good point, as I wrote in the Additional information
In a further PR, the visibility of the whole display should be configurable, allowing for settings Everyone/Admins/Disabled
I was planning a separate PR to allow disabling the whole feature, but probably it's better to also allow disabling only the models part. Anyway, the display of currently running models is not new, it was just not working reliably before. What is new is the display of total and per-model running requests.
For the moment, it is very easy to hard-disable or restrict to admin any of these displays via {#if} conditions in src/lib/components/layout/Sidebar/UserMenu.svelte. A proper implementation would just make these configurable.
@tjbck Are you generally interested in this? I can also separate out a PR that just changes/fixes the usage endpoint/tracking, without any visible changes in the UI.
@Ithanil we're planning on merging this with https://github.com/open-webui/open-webui/issues/6692 internally, appreciate your patience!
@Ithanil we're planning on merging this with #6692 internally, appreciate your patience!
Cool, thanks for letting me know!
👋 Welcome and Thank You for Contributing!
We appreciate you taking the time to submit a pull request to Open WebUI!
⚠️ Important: Testing Requirements
We've recently seen an increase in PRs that have significant issues:
- PRs that don't actually fix the bug they claim to fix
- PRs that don't implement the feature they describe
- PRs that break existing functionality
- PRs that are clearly AI-generated without proper testing being done by the author
- PRs that simply don't work as intended
These untested PRs consume significant time from maintainers and volunteer contributors who review and test PRs in their free time. Time that could be spent testing other PRs or improving Open WebUI in other ways.
Before marking your PR as "Ready for Review":
Please explicitly confirm:
- ✅ You have personally tested ALL changes in this PR
- ✅ How you tested it (specific steps you took to verify it works)
- ✅ Visual evidence where applicable (screenshots or videos showing the feature/fix working) - if applicable to your specific PR
If you're not certain your PR works exactly as intended, please leave it in DRAFT mode until you've thoroughly tested it.
Thank you for helping us maintain quality and respecting the time of our community! 🙏