swanmetrics 1.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- swanmetrics/__init__.py +55 -0
- swanmetrics/_version.py +3 -0
- swanmetrics-1.0.3.data/data/etc/jupyter/jupyter_server_config.d/swanmetrics.json +7 -0
- swanmetrics-1.0.3.dist-info/METADATA +32 -0
- swanmetrics-1.0.3.dist-info/RECORD +7 -0
- swanmetrics-1.0.3.dist-info/WHEEL +4 -0
- swanmetrics-1.0.3.dist-info/entry_points.txt +2 -0
swanmetrics/__init__.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from jupyter_server_proxy.handlers import ProxyHandler
|
|
3
|
+
|
|
4
|
+
from prometheus_client import Counter
|
|
5
|
+
from ._version import __version__
|
|
6
|
+
|
|
7
|
+
from jupyter_server.base.handlers import PrometheusMetricsHandler
|
|
8
|
+
|
|
9
|
+
editors_opened = {
|
|
10
|
+
"vscode": False
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
# Prometheus metrics
|
|
14
|
+
EDITORS_OPEN = Counter(
|
|
15
|
+
"swan_editor_open",
|
|
16
|
+
"Code editor usage in SWAN",
|
|
17
|
+
["editor"]
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
_original_prepare = ProxyHandler.prepare
|
|
21
|
+
def _wrapped_prepare(self, *args, **kwargs):
|
|
22
|
+
path = self.request.path
|
|
23
|
+
for editor, visited in editors_opened.items():
|
|
24
|
+
if editor in path and not visited:
|
|
25
|
+
EDITORS_OPEN.labels(editor=editor).inc()
|
|
26
|
+
editors_opened[editor] = True
|
|
27
|
+
return _original_prepare(self)
|
|
28
|
+
ProxyHandler.prepare = _wrapped_prepare
|
|
29
|
+
|
|
30
|
+
def _load_jupyter_server_extension(server_app) -> None:
|
|
31
|
+
"""
|
|
32
|
+
Extension entry point. Called by Jupyter Server on startup.
|
|
33
|
+
"""
|
|
34
|
+
log = server_app.log
|
|
35
|
+
log.info(f"SwanMetrics: Loading version v{__version__}")
|
|
36
|
+
|
|
37
|
+
web_app = server_app.web_app
|
|
38
|
+
|
|
39
|
+
# Add route for Prometheus handler at the root level
|
|
40
|
+
# so that Prometheus always scrapes the same endpoint,
|
|
41
|
+
# without having to access /user/<username>/metrics every time.
|
|
42
|
+
|
|
43
|
+
web_app.add_handlers(
|
|
44
|
+
r".*$",
|
|
45
|
+
[(r"/metrics", PrometheusMetricsHandler)]
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _jupyter_server_extension_points():
|
|
50
|
+
"""
|
|
51
|
+
Returns the extension metadata for jupyter_server.
|
|
52
|
+
|
|
53
|
+
This is required for `jupyter server extension enable` to work.
|
|
54
|
+
"""
|
|
55
|
+
return [{"module": "swanmetrics"}]
|
swanmetrics/_version.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swanmetrics
|
|
3
|
+
Version: 1.0.3
|
|
4
|
+
Summary: Jupyter Server extension for collecting metrics via jupyter_events
|
|
5
|
+
Author-email: SWAN Team <swan-admins@cern.ch>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: jupyter-events==0.12.0
|
|
9
|
+
Requires-Dist: jupyter-server==2.15.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# SwanMetrics
|
|
13
|
+
|
|
14
|
+
SWAN Metrics extension to add metrics for specific user actions, such as opening editors.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
* jupyter_server
|
|
20
|
+
* jupyter_events
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install swanmetrics
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Observations
|
|
29
|
+
|
|
30
|
+
* The `/metrics` route was added to direct the `PrometheusMetricsHandler` to the root url, so that Prometheus always scrapes the same endpoint,
|
|
31
|
+
without having to access the `/user/<username>/metrics` endpoint every time. Otherwise, the username would have to be parsed each time Prometheus
|
|
32
|
+
would scrape the metrics from the user pod.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
swanmetrics/__init__.py,sha256=iN7u09LaGNifsUxB3A114LhBJT86-QGR9VBpkyBGO40,1539
|
|
2
|
+
swanmetrics/_version.py,sha256=TwPzof9L7jlosL2jMexzNnnv8eLO1skGscq6zLtpok8,103
|
|
3
|
+
swanmetrics-1.0.3.data/data/etc/jupyter/jupyter_server_config.d/swanmetrics.json,sha256=O-mGTsTJWTrDJb0qqDC3nOQJXz8B4bm1ZRMCsurRco0,103
|
|
4
|
+
swanmetrics-1.0.3.dist-info/METADATA,sha256=rl8KhubYfeMVdfaYwfCvQPfY8pVv0iVF6H8QzGxDR3k,901
|
|
5
|
+
swanmetrics-1.0.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
6
|
+
swanmetrics-1.0.3.dist-info/entry_points.txt,sha256=_30ZxQbsnpYomPNf9xJyue3mOlRAWuuPIDl38NUjBLQ,85
|
|
7
|
+
swanmetrics-1.0.3.dist-info/RECORD,,
|