Skip to content

Commit 807c8cf

Browse files
committed
Emptied out 'murfey.server.api.__init__'; migrated 'inspect_prometheus_metrics()' to 'murfey.server.api.prometheus'
1 parent dfacae2 commit 807c8cf

File tree

2 files changed

+31
-41
lines changed

2 files changed

+31
-41
lines changed

src/murfey/server/api/__init__.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +0,0 @@
1-
from __future__ import annotations
2-
3-
import logging
4-
from typing import Optional
5-
6-
from fastapi import APIRouter, Depends
7-
from prometheus_client import Counter, Gauge
8-
9-
import murfey.server.prometheus as prom
10-
from murfey.server.api.auth import validate_token
11-
12-
log = logging.getLogger("murfey.server.api")
13-
14-
router = APIRouter(dependencies=[Depends(validate_token)])
15-
16-
17-
@router.get("/prometheus/{metric_name}")
18-
def inspect_prometheus_metrics(
19-
metric_name: str,
20-
):
21-
"""
22-
A debugging endpoint that returns the current contents of any Prometheus
23-
gauges and counters that have been set up thus far.
24-
"""
25-
26-
# Extract the Prometheus metric defined in the Prometheus module
27-
metric: Optional[Counter | Gauge] = getattr(prom, metric_name, None)
28-
if metric is None or not isinstance(metric, (Counter, Gauge)):
29-
raise LookupError("No matching metric was found")
30-
31-
# Package contents into dict and return
32-
results = {}
33-
if hasattr(metric, "_metrics"):
34-
for i, (label_tuple, sub_metric) in enumerate(metric._metrics.items()):
35-
labels = dict(zip(metric._labelnames, label_tuple))
36-
labels["value"] = sub_metric._value.get()
37-
results[i] = labels
38-
return results
39-
else:
40-
value = metric._value.get()
41-
return {"value": value}

src/murfey/server/api/prometheus.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
from __future__ import annotations
2+
13
from logging import getLogger
4+
from typing import Optional
25

36
from fastapi import APIRouter, Depends
7+
from prometheus_client import Counter, Gauge
48
from sqlmodel import select
59

610
import murfey.server.prometheus as prom
@@ -90,3 +94,30 @@ def increment_rsync_transferred_files_prometheus(
9094
def change_monitoring_status(visit_name: str, on: int):
9195
prom.monitoring_switch.labels(visit=visit_name)
9296
prom.monitoring_switch.labels(visit=visit_name).set(on)
97+
98+
99+
@router.get("metrics/{metric_name}")
100+
def inspect_prometheus_metrics(
101+
metric_name: str,
102+
):
103+
"""
104+
A debugging endpoint that returns the current contents of any Prometheus
105+
gauges and counters that have been set up thus far.
106+
"""
107+
108+
# Extract the Prometheus metric defined in the Prometheus module
109+
metric: Optional[Counter | Gauge] = getattr(prom, metric_name, None)
110+
if metric is None or not isinstance(metric, (Counter, Gauge)):
111+
raise LookupError("No matching metric was found")
112+
113+
# Package contents into dict and return
114+
results = {}
115+
if hasattr(metric, "_metrics"):
116+
for i, (label_tuple, sub_metric) in enumerate(metric._metrics.items()):
117+
labels = dict(zip(metric._labelnames, label_tuple))
118+
labels["value"] = sub_metric._value.get()
119+
results[i] = labels
120+
return results
121+
else:
122+
value = metric._value.get()
123+
return {"value": value}

0 commit comments

Comments
 (0)