mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #1152] [Usage]: mem_cache_hit_nums and mem_cache_nums metrics not exposed via /metrics endpoint #385
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#385
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tianlang-wq on GitHub (Dec 2, 2025).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/1152
Describe your usage question
Background
I built and deployed Mooncake based on the following PR:
👉 https://github.com/kvcache-ai/Mooncake/pull/1020
This PR introduces new metrics:
mem_cache_hit_nums
mem_cache_nums
file_cache_hit_nums
file_cache_nums
I would like to scrape these metrics using Prometheus via the /metrics endpoint to calculate memory/file cache hit ratios.
Problem
Currently, these metrics are available only via the client API, but they are not exposed through the /metrics HTTP endpoint.
Therefore, Prometheus cannot scrape them, making it impossible to compute cache hit ratios using Prometheus.
Expected Behavior
The new cache metrics should be included in the serialized metrics output so that Prometheus can scrape them.
Proposed Fix
I found that the following changes in
mooncake-store/src/master_metric_manager.cpp (inside serialize_metrics()) enable the metrics to appear in /metrics:
serialize_metric(mem_cache_hit_nums_);
serialize_metric(file_cache_hit_nums_);
serialize_metric(mem_cache_nums_);
serialize_metric(file_cache_nums_);
After adding these lines, Prometheus successfully scraped all four metrics.
Questions
Is this the correct and intended approach?
The change appears consistent with how other metrics are exposed.
Can this change be officially supported and merged into the main branch?
This would allow Prometheus users to compute cache hit ratios without relying on the client API.
Is there any concern about exposing these metrics via the /metrics endpoint, such as performance overhead or API compatibility?
Before submitting a new issue...
@tianlang-wq commented on GitHub (Dec 2, 2025):
During validation, I noticed an issue:
mem_cache_hit_nums_ increments every time a cache hit occurs.
mem_cache_nums_ records the current number of KV entries stored in memory.
Analysis
In the calculate_cache_stats() method, the cache hit rate is computed as:
mem_cache_hit_nums_ / mem_cache_nums_
This seems incorrect.
The number of current KV entries is not a meaningful denominator for a hit-rate calculation.
A proper cache hit rate should use:
cache_hits / total_requests
For example, master_exist_key_requests_total would be a more reasonable denominator.
@ykwd commented on GitHub (Dec 2, 2025):
Exposing cache hit rate to Prometheus looks good to me. I am also curious why we expose these metrics in the client side (by querying the master) instead of directly exposing them on the master side. @Liziqi-77 Could you help take a look?
@ykwd commented on GitHub (Dec 2, 2025):
It seems we’ve already discussed this issue here: https://github.com/kvcache-ai/Mooncake/issues/1136#issuecomment-3588429432
If anything in that description is unclear, feel free to point it out and we can take a closer look together.
@tianlang-wq commented on GitHub (Dec 3, 2025):
I took a closer look and realized I made a mistake. Sorry about that, haha.
@ykwd commented on GitHub (Dec 3, 2025):
No worries at all ^_^
@Liziqi-77 commented on GitHub (Dec 3, 2025):
Thank you very much for pointing out this issue. As you mentioned, the denominator counts repeatedly when calculating hit rate. I'm already fixing this bug and will submit an issue to track it.
@tianlang-wq commented on GitHub (Dec 3, 2025):
Is there a link for ISS?
@Liziqi-77 commented on GitHub (Dec 3, 2025):
sure, duplicate counts for mem_cache_hits and ssd_cache_hits.
@tianlang-wq commented on GitHub (Dec 3, 2025):
Thank you very much for your help
@ykwd commented on GitHub (Dec 3, 2025):
@tianlang-wq I just had a discussion with @Liziqi-77. The original reason for exposing the interface only on the client side was concern that the master would need to start an additional HTTP service. But since the master already has an HTTP service, and it already provides a serialization interface for Prometheus, adding this parameter to the serialized metrics is completely fine.
@tianlang-wq commented on GitHub (Dec 3, 2025):
Thank you very much. I saw that https://github.com/kvcache-ai/Mooncake/issues/1160
is about adding metrics for the master server — really looking forward to it.