MS Service Metric¶
MS Service Metric collects vLLM Ascend runtime metrics through function hooks and exposes them in Prometheus format. Install ms_service_metric separately before using this integration; vLLM Ascend itself does not require it to run inference.
For installation, configuration syntax, and complete usage, see the MS Service Metric documentation.
Basic Usage¶
Enable metric collection before starting the service:
export PROMETHEUS_MULTIPROC_DIR=/dev/shm/vllm_metrics
mkdir -p "$PROMETHEUS_MULTIPROC_DIR"
ms-service-metric on
vllm serve <model-path>
PROMETHEUS_MULTIPROC_DIR stores the Prometheus multiprocess metric files. Use a separate directory for each service instance. Before restarting a service for validation, remove stale files only after confirming that no running service is using the directory.
After sending inference requests, query the vLLM metrics endpoint:
The output can be scraped by Prometheus and visualized in Grafana. Use ms-service-metric off to disable collection.
Metric Level¶
Ascend-owned handlers record a MetricSpec only when its level is less than or equal to the active level. Hooks stay installed for the life of the process. The next sample in that process uses the new level.
| Value | Name | Recorded metrics |
|---|---|---|
0 |
basic |
Default. Low-overhead, frequently consulted metrics |
1 |
detail |
basic, plus specs declared at detail (per-step durations and other more expensive metrics) |
How to pick a level for a new metric (read this before adding a point): the level is decided by weighing the metric's collection overhead against how often it is consulted. Metrics that are cheap to collect or commonly watched on dashboards belong at basic. Metrics with per-step sampling, high cardinality, or host-side computation cost belong at detail, so they stay dark in the default deployment and are only turned on while debugging. When in doubt, start at detail.
Set it in runtime_config.json, the same file as ascend_log:
basic, detail, and 0 through 1 are accepted. The stored value is the name. With runtime_config_hot_reload=true, the next apply writes that name into the process-local level: startup, the API / EngineCore file poll, and the worker wave-head cascade. Each process keeps its own integer. An invalid level rejects that load and leaves the previous level in place.
Change the level on a running server:
The API server sends a utility RPC to every EngineCore, the same path as POST /sleep. Each EngineCore sets its own level (scheduler metrics run there) and broadcasts set_metrics_level to its workers, including pipeline stages that do not run the wave-head reload. The response is {"status": "ok", "level": "detail"}. An unknown level returns HTTP 400.
Do not mix the two channels. The endpoint sets the level in memory only; it does not write
metrics.levelback toruntime_config.json. The file and the endpoint are separate channels — pick one per deployment. If you use the endpoint and then editruntime_config.jsonafterwards (even an unrelated key), the file edit changes the digest, the next poll re-applies the whole file, andmetrics.levelsilently resets to the file's stale value with no trace in the changes log. To make a level survive a restart or a file edit, put it inruntime_config.json(oradditional_config.runtime_config) instead of calling the endpoint.
This level applies to handlers that record through vllm_ascend.observability.ms_metrics.handlers.common. Metrics emitted by ms_service_metric.provider_handlers (scheduler, model-runner phase, and memory) follow the ms-service-metric on/off switch. Lowering the level stops new samples. Series already created in the Prometheus registry remain until the process exits.
Declare level on a new expensive metric. The default is basic:
from vllm_ascend.observability.ms_metrics.handlers.common import METRIC_LEVEL_DETAIL
MetricSpec(
"example:per_layer:value",
MetricType.GAUGE,
("rank", "layer"),
level=METRIC_LEVEL_DETAIL,
)
Custom Metric Configuration¶
Set MS_SERVICE_METRIC_CONFIG_PATH before starting vLLM. It can point to either one YAML file or a directory containing multiple YAML files:
# Load one YAML file.
export MS_SERVICE_METRIC_CONFIG_PATH=/data/custom_metrics/custom.yaml
# Or load all first-level .yaml and .yml files in one directory.
export MS_SERVICE_METRIC_CONFIG_PATH=/data/custom_metrics
ms-service-metric on
vllm serve <model-path>
Directory mode loads first-level .yaml and .yml files in filename order and does not scan subdirectories recursively. The configured directory is also the root for external Handler modules referenced by module:function in these YAML files. Users are responsible for maintaining their custom YAML files and Handler implementations.
Run ms-service-metric restart after changing YAML configuration. Restart the vLLM service after changing Handler Python code because imported Python modules are not reloaded dynamically.
Adding a Metric Point¶
vLLM Ascend-owned metric configurations are stored as YAML files in vllm_ascend/observability/ms_metrics/config/, one YAML file per feature. All YAML files in this directory are loaded automatically.
- Identify the target function and add its fully qualified
module:Class.methodname assymbol. - Reuse a stable handler from
ms_service_metric.provider_handlerswhen it provides the required data processing. - For Ascend-specific processing, add a handler module
vllm_ascend/observability/ms_metrics/handlers/<feature>.py, re-export the handler inhandlers/__init__.py, and reference it asvllm_ascend.observability.ms_metrics.handlers:function_name. Reuse the shared helpers inhandlers/common.pyinstead of re-implementing them: declare each metric as aMetricSpec(name, type, label names, and optionallevel) and pass the specs toregister_metrics. Pick thelevelby the rule in Metric Level — overhead versus how often the metric is consulted. Record samples withrecord_metric, and skip expensive collection whenmetric_enabled(spec)is false. Wrap recording code insafe_recordingfor failure isolation.common.pyis the only module that importsms_service_metric, so feature handlers takeMetricTypeand the helpers from there. - Since we are using a custom handler, metrics cannot be configured in the YAML file. Declare the metric in code as a
MetricSpec(step 3) — a custom handler entry must contain onlysymbolandhandler. Then updatetests/ut/observability/test_ms_metrics_provider.py.
A metrics block is only valid for entries that reference a provider built-in handler (e.g. ms_service_metric.provider_handlers:*), which follows the framework's factory convention. A custom handler with a metrics block is treated as a factory, fails the factory call, and silently falls back to a pass-through hook, so the metric is never recorded.
Example of a custom handler entry:
- symbol: vllm_ascend.worker.v2.model_runner:NPUModelRunner.sample_tokens
handler: vllm_ascend.observability.ms_metrics.handlers:sample_tokens_handler
Example of a provider built-in entry, which keeps its metrics block:
- symbol: vllm_ascend.worker.v2.model_runner:NPUModelRunner.execute_model
handler: ms_service_metric.provider_handlers:model_runner_phase_handler
metrics:
- name: executor:model_runner_execute_model:duration
type: histogram
Keep configurations and handlers aligned with the vLLM Ascend implementation. A missing symbol disables only the affected metric and must not affect inference.