Using with Prometheus
This chapter guides users through installing and deploying Prometheus-related software, and viewing resource monitoring data information through Prometheus. For details about the data information, see Prometheus Metrics API.
- Directly Connecting to Prometheus: NPU Exporter can directly import NPU device data information into Prometheus without additional middleware or agents, resulting in a simpler architecture.
- Connecting to Prometheus via Prometheus Operator: NPU Exporter connects to Prometheus through the Prometheus Operator plugin, helping users quickly and easily platformize the Prometheus service, improving the reliability and maintainability of the monitoring system.
Go to the mindcluster-deploy repository, switch to the corresponding branch according to the mindcluster-deploy Open-Source Repository Version Description, and obtain the
prometheus.yamlfile in thesamples/utils/prometheus/basedirectory.Run the following command on the management node to obtain the image.
docker pull prom/prometheus:v2.10.0NOTE
- Before obtaining the image, ensure that you can access the internet normally.
- If you do not use the
prometheus.yamlfile provided by MindCluster, refer to this YAML and add theapp: prometheusfield in the corresponding location. Otherwise, NPU Exporter connection may time out.
The
prometheus.yamlfile already includes the default configuration for obtaining NPU Exporter metrics. You can modify the corresponding configuration as needed. The content starting fromjob_namebelow is the configuration for obtaining NPU Exporter metrics.... apiVersion: v1 kind: ConfigMap metadata: name: prometheus-config namespace: kube-system data: prometheus.yml: | global: scrape_interval: 15s evaluation_interval: 15s scrape_configs: ... - job_name: 'kubernetes-npu-exporter' kubernetes_sd_configs: - role: pod scheme: http relabel_configs: - action: keep source_labels: [__meta_kubernetes_namespace] regex: npu-exporter - source_labels: [__meta_kubernetes_pod_node_name] target_label: job replacement: ${1} ...Run the following command to label the management node.
kubectl label nodes <Hostname of the management node> masterselector=dls-master-node --overwrite=trueUpload
prometheus.yamlto any path on the node in step 2.In the directory where
prometheus.yamlis stored, run the following command to install the Prometheus service.kubectl apply -f prometheus.yamlThe sample output is as follows, which indicates a successful installation.
[root@centos check_env]# kubectl apply -f prometheus.yaml clusterrole.rbac.authorization.k8s.io/prometheus created serviceaccount/prometheus created clusterrolebinding.rbac.authorization.k8s.io/prometheus created service/prometheus created deployment.apps/prometheus created configmap/prometheus-config createdRun the following command to check whether Prometheus has started successfully.
kubectl get pods --all-namespaces | grep prometheusThe sample output is as follows. A
Runningstatus indicates that Prometheus has started successfully.kube-system prometheus-58c69548b4-rhxsc 1/1 Running 0 6d14hLog in to the Prometheus service and view the monitored data information.
Open a browser.
Enter
http://management node IP address:port numberin the browser and pressEnter.Find the
nodePortfield in theprometheus.yamlfile. The value of this field is the port number of the Prometheus service, which defaults to30003.Select the relevant NPU labels to view the corresponding data information.
Run the following command to obtain the Prometheus Operator plugin source code.
git clone https://github.com/prometheus-operator/kube-prometheus.git- Refer to the compatibility list in the official documentation to obtain the Prometheus Operator source code branch that matches your K8s version.
- If Prometheus Operator and Prometheus are already installed, you can proceed directly to step 4.
Install the Prometheus Operator plugin.
Run the following command to install Prometheus Operator.
kubectl create -f manifests/setup/The sample output is as follows, which indicates that Prometheus Operator has been installed successfully.
namespace/monitoring created ... deployment.apps/prometheus-operator created service/prometheus-operator created serviceaccount/prometheus-operator createdRun the following command to check whether Prometheus Operator has started successfully.
kubectl get pod -A -o wide|grep prometheus-operatorThe sample output is as follows. A
Runningstate indicates that Prometheus Operator has started successfully.monitoring prometheus-operator-7649c7454f-wp84n 2/2 Running 0 58s 192.168.xx.xx node133 <none> <none>
Install Prometheus.
Go to the mindcluster-deploy repository, switch to the corresponding branch according to mindcluster-deploy Open-Source Repository Version Description, and obtain the
prometheus.yamlfile from thesamples/utils/prometheus/basedirectory.Upload the
prometheus.yamlobtained in Step 1 to any path in the environment.In the directory where
prometheus.yamlis stored, run the following command to install Prometheus.kubectl apply -f prometheus.yamlThe sample output is as follows, which indicates a successful installation.
service/prometheus created prometheus.monitoring.coreos.com/prometheus created serviceaccount/prometheus-service-account created clusterrole.rbac.authorization.k8s.io/prometheus-cluster-role created clusterrolebinding.rbac.authorization.k8s.io/prometheus-cluster-role-binding createdRun the following command to check whether Prometheus has started successfully.
kubectl get pods --all-namespaces | grep prometheusSample output:
kube-system prometheus-prometheus-0 2/2 Running 1 3m47s 192.168.xx.xx node133 <none> <none> monitoring prometheus-operator-7649c7454f-wp84n 2/2 Running 0 5m52s 192.168.xx.xx node133 <none> <none>
Connect NPU Exporter to Prometheus through Prometheus Operator.
Obtain npu-exporter-svc.yaml and servicemonitor.yaml.
NOTE If Prometheus has been installed in advance, ensure that the following fields in
servicemonitor.yamlare consistent withmatchLabelsconfigured inserviceMonitorSelectorof the deployed Prometheus.... labels: serviceMonitorSelector: prometheus ...matchLabelscan be queried by running the following command.kubectl describe pod <pod-name>(Optional) Modify the labels of NPU Exporter based on the actual situation. If no modification is required, skip this step.
In
npu-exporter-svc.yaml, modify the labels based on the actual situation.apiVersion: v1 kind: Service metadata: namespace: npu-exporter # The namespace is npu-exporter name: npu-exporter labels: app: npu-exporter-svc # Labels of the NPU Exporter service spec: type: ClusterIP ports: - port: 8082 # Service port number of NPU Exporter targetPort: 8082 ...In
servicemonitor.yaml, modify the labels of NPU Exporter according to the actual situation, and ensure that the modifications are consistent with those innpu-exporter-svc.yaml.... spec: endpoints: - interval: 10s targetPort: 8082 # Service port number of NPU Exporter path: /metrics namespaceSelector: matchNames: - npu-exporter # The namespace is npu-exporter selector: matchLabels: app: npu-exporter-svc # Labels of the NPU Exporter service
Run the following commands in sequence to connect NPU Exporter to Prometheus through Prometheus Operator.
kubectl apply -f servicemonitor.yaml kubectl apply -f npu-exporter-svc.yamlRun the following command to check whether NPU Exporter is successfully connected to Prometheus Operator.
kubectl get svc -A|grep npu-exporterThe sample output is as follows, which indicates that NPU Exporter is successfully connected to Prometheus Operator.
npu-exporter npu-exporter ClusterIP 10.98.xx.xx <none> 8082/TCP 31sRun the following command to check whether Prometheus Operator is successfully connected to Prometheus.
kubectl get servicemonitor -A|grep npu-exporterThe sample output is as follows, which indicates that Prometheus Operator is successfully connected to Prometheus.
kube-system npu-exporter 55s
Log in to the Prometheus service to view the monitored data information.
Open a browser.
Enter
http://management node IP address:port number" in the browser and pressEnter.Find the
nodePortfield in theprometheus.yamlfile. The value of this field is the port number of the Prometheus service, which defaults to30003.Select the relevant labels for the NPU to view the corresponding data information.