# k8s_examples_gpu-service-monitor-gke.yaml
# This ServiceMonitor tells the Prometheus Operator how to discover and scrape
# metrics from the NVIDIA DCGM Exporter. It is designed to find the
# 'gke-managed-dcgm-exporter' Service in the 'gke-managed-system' namespace
# and scrape its '/metrics' endpoint.
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: nvidia-dcgm-exporter-servicemonitor
  namespace: monitoring
  labels:
    # This label is used by the Prometheus Operator to discover this
    # ServiceMonitor. It must match the 'serviceMonitorSelector' configured
    # in the Prometheus custom resource.
    release: prometheus
spec:
  # This selector identifies the specific Service to scrape. It must match
  # the labels on the 'gke-managed-dcgm-exporter' Service.
  selector:
    matchLabels:
      # GKE-SPECIFIC: This label matches the Service for GKE's managed DCGM
      # exporter. If you are using a different DCGM daemon, you must
      # update this label to match the label of the corresponding Service.
      app.kubernetes.io/name: gke-managed-dcgm-exporter
  # This selector specifies which namespace to search for the target Service.
  # For GKE, the DCGM service is in 'gke-managed-system'.
  namespaceSelector:
    matchNames:
    # GKE-SPECIFIC: This is the namespace for GKE's managed DCGM exporter.
    # For other environments, this should be the namespace where you have
    # deployed the DCGM exporter Service.
    - gke-managed-system
  endpoints:
  - port: metrics
    interval: 15s