自定义指标示例#

在本节中,我们演示了 Python 后端中 自定义指标 API 的端到端示例。 模型仓库 应包含 custom_metrics 模型。 custom_metrics 模型使用 自定义指标 API 来注册和收集自定义指标。

部署自定义指标模型#

  1. 创建模型仓库

mkdir -p models/custom_metrics/1/

# Copy the Python models
cp examples/custom_metrics/model.py models/custom_metrics/1/model.py
cp examples/custom_metrics/config.pbtxt models/custom_metrics/config.pbtxt
  1. 启动 tritonserver

tritonserver --model-repository `pwd`/models
  1. 向服务器发送推理请求

python3 examples/custom_metrics/client.py

在客户端终端中,您应该看到类似于以下输出的输出

custom_metrics example: found pattern '# HELP requests_process_latency_ns Cumulative time spent processing requests' in metrics
custom_metrics example: found pattern '# TYPE requests_process_latency_ns counter' in metrics
custom_metrics example: found pattern 'requests_process_latency_ns{model="custom_metrics",version="1"}' in metrics
PASS: custom_metrics

在运行 Triton 服务器的终端中,您应该看到类似于以下输出的输出

Cumulative requests processing latency: 223406.0

model.py 模型文件包含大量注释,解释了每个函数调用的作用。

客户端输出说明#

client.py 发送一个 HTTP 请求,URL 为 https://127.0.0.1:8002/metrics,以从 Triton 服务器获取指标。然后,客户端验证模型文件中添加的自定义指标是否被正确报告。