# A ServiceMonitor is a Kubernetes object that defines how Prometheus should monitor a specific service running in a Kubernetes cluster.
#ServiceMonitor allows Prometheus to automatically discover and scrape metrics from services that are running in the same Kubernetes cluster.
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: ms-demo-service-monitor
  namespace: monitoring
spec:
  endpoints: #This field specifies the endpoints that Prometheus should scrape for metrics. You can specify the port, path, and other information for each endpoint.
    - interval: 15s
      port: ms-metrics
      scrapeTimeout: 14s
      path: /actuator/prometheus
  namespaceSelector:
    matchNames:
      - default
  selector: #This field specifies how Prometheus should discover the target service to monitor. You can use labels, namespaces, and other selectors to choose the target service.
    matchLabels:
      app.kubernetes.io/part-of: ms-demo-svc

#ref: https://dev.to/apgapg/creating-a-service-monitor-in-k8s-nl8
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: hello2-service-monitor
  namespace: monitoring
spec:
  endpoints: #This field specifies the endpoints that Prometheus should scrape for metrics. You can specify the port, path, and other information for each endpoint.
    - interval: 15s
      port: hello2-metrics
      scrapeTimeout: 14s
      path: /actuator/prometheus
  namespaceSelector:
    matchNames:
      - default
  selector: #This field specifies how Prometheus should discover the target service to monitor. You can use labels, namespaces, and other selectors to choose the target service.
    matchLabels:
      app.kubernetes.io/part-of: hello-world-two-svc
