使用Prometheus操作员进行自定义监控

时间:2019-09-07 09:55:53

标签: kubernetes monitoring grafana prometheus prometheus-operator

我在k8s的每个命名空间(stg,pre和production)中都有6个nginx副本。现在,我想废弃所有的nginx状态代码(例如200,300,400,500),并对其进行计数,并显示在prometheus和grafana中。有什么方法可以在运算符中添加自定义监视spces?

1 个答案:

答案 0 :(得分:0)

这应该很简单,就像在values.yaml中添加additionalServiceMonitors一样,当然,我假设您的Nginx已经使用状态码信息公开了这些指标。

示例:

k apply -f -<<EOF
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  annotations:
  labels:
    release: prom
  name: kafka-exporter
spec:
  endpoints:
  - port: metrics
  selector:
    matchLabels:
      app: kafka-exporter
EOF
k apply -f -<<EOF
apiVersion: v1
kind: Service
metadata:
  labels:
    app: kafka-exporter
    role: kafka
  name: kafka
spec:
  ports:
  - name: server
    port: 9093
    protocol: TCP
    targetPort: 9093
  - name: metrics
    port: 9182
    protocol: TCP
    targetPort: 9182
  selector:
    role: kafka
EOF