1. Expose a Metrics Endpoint in the Training Code
The training code must expose ports and paths, ensuring that they match the metrics endpoints configured when the task is created. The following example exposes/metrics through two ports in the same training task.
Code example:
The metric update logic in the example is for demonstration purposes only. In actual integration, replace it with real business data from the training code, and ensure that the port and path exposed by the code are consistent with the metric endpoint specified when creating the task.
View Python Sample Code
View Python Sample Code
2. Create a Training Task and Configure the Metrics Endpoint
When creating a training task, enable Metrics Monitor under Advanced Options and configure metrics endpoints for the ports exposed by the training code.
If you need to collect data from multiple endpoints, click Add Metrics Endpoint to add them one by one. Within the same training task, each combination of Metrics Port and Metrics Path must be unique. Based on the example above, add the following two endpoints.
For other configuration options for creating a training task, see Create Training.
3. Verify the Metrics Endpoint
After the task starts running, access the corresponding metrics endpoint within the training task container and verify that the endpoint can return metric samples.View Response Example
View Response Example
4. Configure and View Custom Metrics Charts
After the metrics endpoint collects data, go to the training task details page and open the Monitoring tab. Select Custom on the left, then configure charts based on the metric name and label to view the corresponding curves. The available modules, submodules, and classes may vary by environment; refer to the console for the actual options. When configuring, pay particular attention to the following fields.
When configuring the Legend and PromQL, you can use the metric’s own business labels or labels added by the platform, such as Pod, scrape endpoint, and container labels. Common labels are as follows.
Available labels are subject to the metrics actually exposed by the current task and those displayed in the console.
The following example shows how to configure a chart for
myapp_http_requests_total:
Troubleshoot No Data for Custom Metrics
If there is no data in Monitoring > Custom, troubleshoot in the following order:- Ensure that Metrics Monitor was enabled when the training task was created, and that the port and path match the training code.
- Ensure that the training code exposes a metrics endpoint and that metrics are generated while the task is running.
- Access the corresponding metrics endpoint from within the training task container and verify that the endpoint can return metric samples.
- If multiple metrics endpoints are configured, check each port and path separately.
- Refresh later or expand the time range and check again.

