Skip to content

Commit 5c1c57d

Browse files
committed
fix: populate metrics to allow metrics to be queried
1 parent ee3858b commit 5c1c57d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

api/server/metrics.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def first_lvl_du():
8787
try:
8888
dirs = os.listdir(MONITOR_FIRSTLVL_DIR)
8989
except Exception as e:
90-
general_logger.warn(f"Failed to listdir of {MONITOR_FIRSTLVL_DIR}: {str(e)}")
90+
general_logger.warning(f"Failed to listdir of {MONITOR_FIRSTLVL_DIR}: {str(e)}")
9191
return
9292

9393
for dir in dirs:
@@ -99,7 +99,7 @@ def first_lvl_du():
9999
size_b, *_ = result.stdout.split("\t")
100100
Singleton.cached_du[dir] = int(size_b)
101101
except Exception as e:
102-
general_logger.warn(f"Failed to check du of {str(path_to_dir)}: {str(e)}")
102+
general_logger.warning(f"Failed to check du of {str(path_to_dir)}: {str(e)}")
103103

104104
@staticmethod
105105
@cron.minutely
@@ -199,6 +199,20 @@ def refresh_metric():
199199

200200
def on_startup():
201201
"""On startup"""
202+
203+
# Set cached_metrics first
204+
# Populating metrics takes a while
205+
206+
from prometheus_client import Gauge, CollectorRegistry, generate_latest
207+
registry = CollectorRegistry()
208+
common_kwargs = {
209+
'registry':registry,
210+
'namespace':NAME_SPACE,
211+
}
212+
last_pinged = Gauge("last_pinged", "Last pinged time", labelnames=[], **common_kwargs)
213+
last_pinged.set_to_current_time()
214+
Singleton.cached_metrics = generate_latest(registry)
215+
202216
cron.start()
203217

204218

0 commit comments

Comments
 (0)