Skip to content

Service with dashboard

Back

This example show how to setup Monitoring for collect metrics from service and dashboard for show collected metrics.

ServiceMonitor

spec:
  endpoints:
  - interval: 30s
    port: http
  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 http with interval 30s

Dashboard

spec:
  name: simple-dashboard.json
  json: >
    {
      "id": null,
      "title": "Simple Dashboard",
      ...
      <dashboard content in json format>
      ...
    }

It means that in grafana will import dashboard with name Simple Dashboard.

Files

How to apply example

Kubernetes:

kubectl apply -f service-monitor.yaml
kubectl apply -f dashboard.yaml

OpenShift:

oc apply -f service-monitor.yaml
oc apply -f dashboard.yaml