custom monitoring with prometheus operator

9/7/2019

I have 6 replica of nginx in each of namespaces of k8s (stg,pre and production). now I want to scrap all nginx status code like 200,300,400,500 and count them and show in prometheus and grafana. is there any way to add custom monitoring spces in operator?

-- alireza71
grafana
kubernetes
monitoring
prometheus
prometheus-operator

1 Answer

9/7/2019

It should be as simple as adding additionalServiceMonitors in values.yaml, of course, I am assuming your Nginx already expose these metrics with information about status codes.

Example:

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
-- FL3SH
Source: StackOverflow