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 |
---|
language | yml |
---|
title | serviceMonitor.yaml |
---|
collapse | true |
---|
|
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 |
---|
language | bash |
---|
title | Prometheus CRD |
---|
collapse | true |
---|
|
# This is just an excerpt from the output of the "describe" command
$ kkubectl getdescribe prometheus -n monitoring prometheus -oyaml
spec:
Service Monitor serviceMonitorSelectorSelector:
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.
Section |
---|
Column |
---|
| Image ModifiedLH service monitor
|
Column |
---|
| Image ModifiedLH metrics
|
|