[WIP] implement last_activity collection via prometheus metrics #229
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
two modes:
TODO:
As it currently stands, we have the following configuration:
enables single-replica last_activity via the existing traefik API endpoint.
_collect_last_activity_api
fetches the prometheus metrics endpoint of traefik and parses the relevant metric lines, computing the equivalent of"activity" is registered as an increase in these values since the last collection (in memory, reset on first collection)
requires a prometheus instance configured to collect from traefik, and uses the query:
where
interval
is the number of seconds since the last request. This should produce the same results as above, but handle aggregation across multiple replicas and doesn't require comparison with previous results (increase
handles that).Notably, it seems that websocket messages do not produce measured activity on any traefik metrics: traefik/traefik#10358
Fortunately (or not), JupyterLab still sends tons of API requests even while it is idle, so relying on websocket messages for traffic in 2024 is less critical than it was in the much less resource-intensive days of the classic notebook. But it's still something to be aware of, because active websocket messages are how activity is typically tracked in CHP (e.g. output being produced or execute requests being sent).
Another metric to consider is the
open_connections
metric, which allows us to consider any open websocket connection to be 'currently active'. This means any open tab (even an idle one) would prevent culling. Sometimes that's good, sometimes it's not, which is why Jupyter Server's internal culler has config to select whether this is considered or not.closes #151