使用Prometheus查看Lite Cluster监控指标
Prometheus是一款开源监控工具,ModelArts支持Exporter功能,方便用户使用Prometheus等第三方监控系统获取ModelArts采集到的指标数据。
本章节主要介绍如何通过Prometheus查看Lite Cluster监控指标。
约束限制
- 需要在ModelArts Lite Cluster资源池详情页的配置管理页面中先打开“监控”开关。
- 开通此功能后,兼容Prometheus指标格式的第三方组件可通过API http://<节点IP>:<端口号>/metrics获取ModelArts采集到的指标数据。
- 开通前需要确认使用的端口号,端口号可选取10120~10139范围内的任一端口号,请确认选取的端口号在各个节点上都没有被其他应用占用。
Kubernetes下Prometheus对接ModelArts
- 使用kubectl连接集群,详细操作请参考通过kubectl连接集群。
- 配置Kubernetes的访问授权。
使用任意文本编辑器创建prometheus-rbac-setup.yml,YAML文件内容如下:
该YAML用于定义Prometheus要用到的角色(ClusterRole),为该角色赋予相应的访问权限。同时创建Prometheus所使用的账号(ServiceAccount),将账号与角色进行绑定(ClusterRoleBinding)。
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: prometheus rules: - apiGroups: [""] resources: - pods verbs: ["get", "list", "watch"] - nonResourceURLs: ["/metrics"] verbs: ["get"] --- apiVersion: v1 kind: ServiceAccount metadata: name: prometheus namespace: default --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: prometheus roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: prometheus subjects: - kind: ServiceAccount name: prometheus namespace: default
- 执行如下命令创建RBAC对应的各个资源。
$ kubectl create -f prometheus-rbac-setup.yml clusterrole "prometheus" created serviceaccount "prometheus" created clusterrolebinding "prometheus" created
- 使用任意文本编辑器创建prometheus-config.yml,内容如下。该YAML用于管理Prometheus的配置,部署Prometheus时通过文件系统挂载的方式,容器可以使用这些配置。
apiVersion: v1 kind: ConfigMap metadata: name: prometheus-config data: prometheus.yml: | global: scrape_interval: 10s scrape_configs: - job_name: 'modelarts' tls_config: ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_name] # 指定从maos-node-agent-字符串开头的POD收集指标数据 action: keep regex: ^maos-node-agent-.+ - source_labels: [__address__] # 指定获取指标数据的地址和端口号为__address__:9390,__address__为POD的IP地址,也是节点IP地址 action: replace regex: '(.*)' target_label: __address__ replacement: "${1}:10120"
- 执行如下命令创建ConfigMap资源。
$ kubectl create -f prometheus-config.yml configmap "prometheus-config" created
- 使用任意文本编辑器创建prometheus-deployment.yml,内容如下。
该YAML用于部署Prometheus。将上面创建的账号(ServiceAccount)权限赋予了Prometheus,同时将上面创建的ConfigMap资源以文件系统的方式挂载到了prometheus容器的“/etc/prometheus”目录,并且通过--config.file=/etc/prometheus/prometheus.yml参数指定了“/bin/prometheus”使用该配置文件。
apiVersion: v1 kind: "Service" metadata: name: prometheus labels: name: prometheus spec: ports: - name: prometheus protocol: TCP port: 9090 targetPort: 9090 selector: app: prometheus type: NodePort --- apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: name: prometheus name: prometheus spec: replicas: 1 template: metadata: labels: app: prometheus spec: hostNetwork: true serviceAccountName: prometheus serviceAccount: prometheus containers: - name: prometheus image: prom/prometheus:latest imagePullPolicy: IfNotPresent command: - "/bin/prometheus" args: - "--config.file=/etc/prometheus/prometheus.yml" ports: - containerPort: 9090 protocol: TCP volumeMounts: - mountPath: "/etc/prometheus" name: prometheus-config volumes: - name: prometheus-config configMap: name: prometheus-config
- 执行如下命令创建Prometheus实例,并查看创建情况:
$ kubectl create -f prometheus-deployment.yml service "prometheus" created deployment "prometheus" created $ kubectl get pods NAME READY STATUS RESTARTS AGE prometheus-55f655696d-wjqcl 1/1 Running 0 5s $ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 131d prometheus NodePort 10.101.255.236 <none> 9090:32584/TCP 42s