Skip to content

ServiceMonitor with custom endpoint

Back

This example show a configuration of ServiceMonitor with custom-endpoint.

PodMonitor

spec:
  endpoints:
  - interval: 30s
    port: https
    scheme: https
    path: /v1/my/awesome/endpoint
    params:
        format:
          - prometheus
  jobLabel: k8s-app
  selector:
    matchLabels:
      k8s-app: sample-service

It means that Prometheus will collect metrics from service with settings:

  • metrics will collect with job with label k8s-app
  • metrics will collect from all pods with label k8s-app: sample-service
  • metrics will collect from all discovered pod from port with name https with interval 30s
  • metrics will collect from endpoint /v1/my/awesome/endpoint
  • request for collect metrics will contains URL parameters: format=prometheus

Files

How to apply example

Kubernetes:

kubectl apply -f service-monitor.yaml

OpenShift:

oc apply -f service-monitor.yaml

Prometheus operator API

Victoriametrics operator API