云容器引擎 CCE-使用AOM监控自定义指标:部署应用并转换指标
部署应用并转换指标
如上所述的nginx:exporter提供的监控数据,其数据格式并不满足Prometheus的要求,需要将其转换成Prometheus需要的格式,可以使用nginx-prometheus-exporter来转换Nginx的指标,如下所示。
使用nginx:exporter和nginx-prometheus-exporter部署到同一个Pod,如下所示。
kind: Deployment apiVersion: apps/v1 metadata: name: nginx-exporter namespace: default spec: replicas: 1 selector: matchLabels: app: nginx-exporter template: metadata: labels: app: nginx-exporter annotations: metrics.alpha.kubernetes.io/custom-endpoints: '[{"api":"prometheus","path":"/metrics","port":"9113","names":""}]' spec: containers: - name: container-0 image: 'nginx:exporter' # 替换为您上传到SWR的镜像地址 resources: limits: cpu: 250m memory: 512Mi requests: cpu: 250m memory: 512Mi - name: container-1 image: 'nginx/nginx-prometheus-exporter:0.9.0' command: - nginx-prometheus-exporter args: - '-nginx.scrape-uri=http://127.0.0.1:8080/stub_status' imagePullSecrets: - name: default-secret
nginx/nginx-prometheus-exporter:0.9.0需要从公网拉取,需要集群节点绑定公网IP。
nginx-prometheus-exporter需要一个启动命令,nginx-prometheus-exporter -nginx.scrape-uri=http://127.0.0.1:8080/stub_status,用于获取nginx的监控数据。
另外Pod需要添加一个annotations,metrics.alpha.kubernetes.io/custom-endpoints: '[{"api":"prometheus","path":"/metrics","port":"9113","names":""}]'。