#3556·mlc-llm

[Feature Request] Make /metrics parseable by Prometheus

Author: arjunnaiCreated Sep 29, 2026Updated Sep 29, 2026

Feature

Make the /metrics endpoint parseable by Prometheus.

Motivation

EngineMetrics.prometheus_text() and the labels built in cpp/serve/metrics.cc look like they're meant to follow the Prometheus text format (#2392 reorganized them "by labels in prometheus style"), but the label values aren't quoted:

decode_time_by_batch_size_mean{batch_size=1}	0.01
spec_decode_accept_prob_accept_prob{step=0}	0.5

Prometheus requires {batch_size="1"}. Running the output through prometheus_client's parser fails with Invalid labels: batch_size=1, so once a server has decoded anything, a Prometheus scrape of /metrics fails as a whole.

This would help anyone running mlc_llm serve behind a router or on more than one endpoint and wanting to monitor it.

Alternatives

  • Quote the values where the labels are built in metrics.cc (mean{batch_size="1"}). Smallest change, but the JSON keys in /debug/dump_engine_metrics change too.
  • Leave the C++ keys alone and quote label values in prometheus_text() in Python. JSON output stays the same.

Either way I'd add a small unit test that runs prometheus_text() through the Prometheus parser. Could also add # TYPE lines while at it, if that's wanted.

Additional context

Is /metrics meant to be scraped by Prometheus, or is it mainly a debug printout? Happy to send a PR for whichever approach you prefer.