KServe provides a set of default Prometheus metrics to help you monitor the performance and health of model services. This topic uses the Qwen-7B-Chat-Int8 model and a V100 GPU as an example to show how to configure Prometheus monitoring for the KServe framework.
Prerequisites
-
The Arena client is installed and the version is 0.9.15 or later. For more information, see Configure the Arena client.
-
The Install the ack-kserve add-on is installed.
-
The Managed Service for Prometheus add-on is enabled. For more information, see Enable Prometheus monitoring.
Step 1: Deploy a KServe application
-
Run the following command to deploy a scikit-learn KServe application.
arena serve kserve \ --name=sklearn-iris \ --image=kube-ai-registry.cn-shanghai.cr.aliyuncs.com/ai-sample/kserve-sklearn-server:v0.12.0 \ --cpu=1 \ --memory=200Mi \ --enable-prometheus=true \ --metrics-port=8080 \ "python -m sklearnserver --model_name=sklearn-iris --model_dir=/models --http_port=8080"Expected output:
service/sklearn-iris-metric-svc created # The service named sklearn-iris-metric-svc is created. inferenceservice.serving.kserve.io/sklearn-iris created # KServe InferenceService resource sklearn-iris is created. servicemonitor.monitoring.coreos.com/sklearn-iris-svcmonitor created # ServiceMonitor resource is created to integrate with the Prometheus monitoring system and collect the monitoring data exposed by the sklearn-iris-metric-svc service. INFO[0004] The Job sklearn-iris has been submitted successfully # Job has been submitted to the cluster. INFO[0004] You can run `arena serve get sklearn-iris --type kserve -n default` to check the job statusThe output indicates that Arena has started the deployment of a KServe application that uses a scikit-learn model, with Prometheus monitoring integrated.
-
Run the following command to write the following JSON content to the
./iris-input.jsonfile to prepare the inference input request.cat <<EOF > "./iris-input.json" { "instances": [ [6.8, 2.8, 4.8, 1.4], [6.0, 3.4, 4.5, 1.6] ] } EOF -
Run the following commands to retrieve the IP address of the NGINX Ingress gateway from the cluster and the hostname portion of the externally accessible URL for the InferenceService.
NGINX_INGRESS_IP=`kubectl -n kube-system get svc nginx-ingress-lb -ojsonpath='{.status.loadBalancer.ingress[0].ip}'` SERVICE_HOSTNAME=$(kubectl get inferenceservice sklearn-iris -o jsonpath='{.status.url}' | cut -d "/" -f 3) -
Run the following command to use the Hey stress testing tool to send repeated requests to the application and generate monitoring data.
NoteFor more information about the Hey stress testing tool, see Hey.
hey -z 2m -c 20 -m POST -host $SERVICE_HOSTNAME -H "Content-Type: application/json" -D ./iris-input.json http://${NGINX_INGRESS_IP}:80/v1/models/sklearn-iris:predictExpected output:
The output summarizes the system performance in this test, including key metrics such as processing speed, data throughput, and response latency. These metrics help you evaluate the efficiency and stability of the system.
-
(Optional) Manually retrieve application metrics to verify that they are exposed correctly.
The following example shows how to collect monitoring metrics from a specific Pod associated with
sklearn-irisin an ACK cluster and view the data locally, without logging on to the Pod or exposing its port to an external network.-
Run the following commands to forward port 8080 of the Pod whose name contains sklearn-iris, specified by the
$POD_NAMEvariable, to port 8080 of the local host. Through this port forwarding, requests sent to local port 8080 are transparently forwarded to port 8080 of the Pod.# Get the Pod name. POD_NAME=`kubectl get po|grep sklearn-iris |awk -F ' ' '{print $1}'` # Use port-forward to forward port 8080 of the Pod to the local host. kubectl port-forward pod/$POD_NAME 8080:8080Expected output:
Forwarding from 127.0.0.1:8080 -> 8080 Forwarding from [::1]:8080 -> 8080The output indicates that local connection attempts over both IPv4 and IPv6 are correctly forwarded to port 8080 of the Pod.
-
Enter the following URL in a browser to access port 8080 of the Pod and view the metrics.
http://localhost:8080/metricsExpected output:
The output shows the various performance and status metrics provided by the application in the Pod. This indicates that the request is ultimately forwarded to the application service in the Pod.
-
Step 2: Query KServe application metrics
-
Log on to the ARMS console.
-
In the left-side navigation pane, click Integration Management, and then click Query Dashboards.
-
On the Dashboards page, click the Kubernetes Pod dashboard to go to the Grafana page.
-
In the left-side navigation pane, click Explore, and then enter the query statement
request_predict_seconds_bucketto query application metric values.NoteData collection has a delay of approximately 5 minutes.
After the query is run, the Graph area displays the trend of the
request_predict_seconds_bucketmetric over time as a line chart.
FAQ and solutions
FAQ
How do I verify that data for the request_predict_seconds_bucket metric has been collected?
Solutions
-
Log on to the ARMS console.
-
On the Connected Environments page, click the Container Environment tab, click the name of the target container environment, and then click the Self-Monitoring tab.
-
In the left-side navigation pane, click Targets. If default/sklearn-iris-svcmonitor/0 (1/1 up) is displayed, metric data collection is successful.
References
For more information about the default metrics provided by the KServe framework, see the community documentation KServe Prometheus Metrics.