Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

After installing Prometheus, by connecting to its dashboard, you will notice a list of services already under monitoring: these are useful resources for the functioning of Prometheus itself (e.g. alertmanager, Grafana) or typical of each K8s cluster (apiserver, controller-manager, scheduler). But how do you monitor an application in general?  As As an example, let's try to monitor Longhorn, a distributed block storage system for Kubernetes.

...

Code Block
languageyml
titleserviceMonitor.yaml
collapsetrue
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: longhorn-prometheus-servicemonitor
  namespace: monitoring
  labels:
    release: mon
spec:
  selector:
    matchLabels:
      app: longhorn-manager
  namespaceSelector:
    matchNames:
    - longhorn-system
  endpoints:
  - port: manager

...

Code Block
languagebash
titlePrometheus CRD
collapsetrue
# This is just an excerpt from the output of the "describe" command
$ kkubectl get prometheusdescribe -n monitoring -oyamlprometheus 
spec:
  Service serviceMonitorSelectorMonitor Selector:
    Match matchLabelsLabels:
      releaseRelease:  mon

After a few seconds, connecting to the Target list of the Prometheus dashboard, you will notice a new line. Of course, you will have Longhorn Metrics for Monitoring available to keep your application under control at all times.

...