---
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-server
  namespace: "prometheus"
data:
  alerting_rules.yml: |
    {}
  alerts: |
    {}
  prometheus.yml: |
    global:
      evaluation_interval: 1m
      scrape_interval: 1m
      scrape_timeout: 10s
    rule_files:
      - /etc/config/recording_rules.yml
      - /etc/config/alerting_rules.yml
      - /etc/config/rules
      - /etc/config/alerts
    scrape_configs:
      - job_name: "prometheus"
        static_configs:
          - targets: ['localhost:9090']
      - job_name: kubernetes-apiservers
        kubernetes_sd_configs:
          - role: endpoints
        relabel_configs:
          - action: keep
            regex: default;kubernetes;https
            source_labels:
              - __meta_kubernetes_namespace
              - __meta_kubernetes_service_name
              - __meta_kubernetes_endpoint_port_name
      - job_name: kubernetes-nodes
        kubernetes_sd_configs:
          - role: node
        relabel_configs:
          - action: labelmap
            regex: __meta_kubernetes_node_label_(.+)
          - replacement: kubernetes.default.svc:443
            target_label: __address__
          - regex: (.+)
            replacement: /api/v1/nodes/$1/proxy/metrics
            source_labels:
              - __meta_kubernetes_node_name
            target_label: __metrics_path__
      - job_name: kubernetes-nodes-cadvisor
        kubernetes_sd_configs:
          - role: node
        relabel_configs:
          - action: labelmap
            regex: __meta_kubernetes_node_label_(.+)
          - replacement: kubernetes.default.svc:443
            target_label: __address__
          - regex: (.+)
            replacement: /api/v1/nodes/$1/proxy/metrics/cadvisor
            source_labels:
              - __meta_kubernetes_node_name
            target_label: __metrics_path__
      - job_name: kubernetes-service-endpoints
        kubernetes_sd_configs:
          - role: endpoints
        relabel_configs:
          - action: keep
            regex: true
            source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_scrape
          - action: replace
            regex: (https?)
            source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_scheme
            target_label: __scheme__
          - action: replace
            regex: (.+)
            source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_path
            target_label: __metrics_path__
          - action: replace
            regex: ([^:]+)(?::\d+)?;(\d+)
            replacement: $1:$2
            source_labels:
              - __address__
              - __meta_kubernetes_service_annotation_prometheus_io_port
            target_label: __address__
          - action: labelmap
            regex: __meta_kubernetes_service_label_(.+)
          - action: replace
            source_labels:
              - __meta_kubernetes_namespace
            target_label: kubernetes_namespace
          - action: replace
            source_labels:
              - __meta_kubernetes_service_name
            target_label: kubernetes_name
          - action: replace
            source_labels:
              - __meta_kubernetes_pod_node_name
            target_label: kubernetes_node
      - job_name: kubernetes-service-endpoints-slow
        kubernetes_sd_configs:
          - role: endpoints
        relabel_configs:
          - action: keep
            regex: true
            source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_scrape_slow
          - action: replace
            regex: (https?)
            source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_scheme
            target_label: __scheme__
          - action: replace
            regex: (.+)
            source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_path
            target_label: __metrics_path__
          - action: replace
            regex: ([^:]+)(?::\d+)?;(\d+)
            replacement: $1:$2
            source_labels:
              - __address__
              - __meta_kubernetes_service_annotation_prometheus_io_port
            target_label: __address__
          - action: labelmap
            regex: __meta_kubernetes_service_label_(.+)
          - action: replace
            source_labels:
              - __meta_kubernetes_namespace
            target_label: kubernetes_namespace
          - action: replace
            source_labels:
              - __meta_kubernetes_service_name
            target_label: kubernetes_name
          - action: replace
            source_labels:
              - __meta_kubernetes_pod_node_name
            target_label: kubernetes_node
        scrape_interval: 5m
        scrape_timeout: 30s
      - job_name: prometheus-pushgateway
        honor_labels: true
        kubernetes_sd_configs:
          - role: service
        relabel_configs:
          - action: keep
            regex: pushgateway
            source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_probe
      - job_name: kubernetes-services
        metrics_path: /probe
        params:
          module:
            - http_2xx
        kubernetes_sd_configs:
          - role: service
        relabel_configs:
          - action: keep
            regex: true
            source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_probe
          - source_labels:
              - __address__
            target_label: __param_target
          - replacement: blackbox
            target_label: __address__
          - source_labels:
              - __param_target
            target_label: instance
          - action: labelmap
            regex: __meta_kubernetes_service_label_(.+)
          - source_labels:
              - __meta_kubernetes_namespace
            target_label: kubernetes_namespace
          - source_labels:
              - __meta_kubernetes_service_name
            target_label: kubernetes_name
      - job_name: kubernetes-pods
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - action: keep
            regex: true
            source_labels:
              - __meta_kubernetes_pod_annotation_prometheus_io_scrape
          - action: replace
            regex: (https?)
            source_labels:
              - __meta_kubernetes_pod_annotation_prometheus_io_scheme
            target_label: __scheme__
          - action: replace
            regex: (.+)
            source_labels:
              - __meta_kubernetes_pod_annotation_prometheus_io_path
            target_label: __metrics_path__
          - action: replace
            regex: ([^:]+)(?::\d+)?;(\d+)
            replacement: $1:$2
            source_labels:
              - __address__
              - __meta_kubernetes_pod_annotation_prometheus_io_port
            target_label: __address__
          - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
          - action: replace
            source_labels:
              - __meta_kubernetes_namespace
            target_label: kubernetes_namespace
          - action: replace
            source_labels:
              - __meta_kubernetes_pod_name
            target_label: kubernetes_pod_name
          - action: drop
            regex: Pending|Succeeded|Failed
            source_labels:
              - __meta_kubernetes_pod_phase
      - job_name: kubernetes-pods-slow
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - action: keep
            regex: true
            source_labels:
              - __meta_kubernetes_pod_annotation_prometheus_io_scrape_slow
          - action: replace
            regex: (https?)
            source_labels:
              - __meta_kubernetes_pod_annotation_prometheus_io_scheme
            target_label: __scheme__
          - action: replace
            regex: (.+)
            source_labels:
              - __meta_kubernetes_pod_annotation_prometheus_io_path
            target_label: __metrics_path__
          - action: replace
            regex: ([^:]+)(?::\d+)?;(\d+)
            replacement: $1:$2
            source_labels:
              - __address__
              - __meta_kubernetes_pod_annotation_prometheus_io_port
            target_label: __address__
          - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
          - action: replace
            source_labels:
              - __meta_kubernetes_namespace
            target_label: kubernetes_namespace
          - action: replace
            source_labels:
              - __meta_kubernetes_pod_name
            target_label: kubernetes_pod_name
          - action: drop
            regex: Pending|Succeeded|Failed
            source_labels:
              - __meta_kubernetes_pod_phase
        scrape_interval: 5m
        scrape_timeout: 30s
      - job_name: 'traefik'
        static_configs:
          - targets: ['traefik.kube-system:9000']
      - job_name: 'grafana'
        static_configs:
          - targets: ['grafana.grafana']
      - job_name: 'unifipoller'
        scrape_interval: 30s
        static_configs:
          - targets: ['unifi-poller.unifi-poller:9130']
      - job_name: 'homeassistant'
        scrape_interval: 60s
        metrics_path: /api/prometheus
        authorization:
          type: "Bearer"
          credentials_file: "/prometheus/homeassistant.creds"
        scheme: http
        static_configs:
          - targets: ['homeassistant:8123']
      - job_name: 'pihole'
        static_configs:
          - targets: ['pihole-exporter.pihole.svc.cluster.local:9617']
      - job_name: 'cloudflared'
        scheme: https
        static_configs:
          - targets:
            - "tunnel.${SECRET_DOMAIN}"
            - "tunnel-pi1.${SECRET_DOMAIN}"
            - "tunnel-pi2.${SECRET_DOMAIN}"
            - "traefik.${SECRET_DOMAIN}"
            - "whoami.${SECRET_DOMAIN}"
            - "gaps.${SECRET_DOMAIN}"
            - "grafana.${SECRET_DOMAIN}"
            - "loki.${SECRET_DOMAIN}"
            - "prometheus.${SECRET_DOMAIN}"
            - "pihole.${SECRET_DOMAIN}"
            - "allaboutsecurity.xyz"
            - "code.${SECRET_DOMAIN}"
            - "nodered.${SECRET_DOMAIN}"
            - "influxdb.${SECRET_DOMAIN}"
            - "k3s.${SECRET_DOMAIN}"
            - "live.${SECRET_DOMAIN}"
            - "home.${SECRET_DOMAIN}"
    alerting:
      alertmanagers:
        - kubernetes_sd_configs:
          - role: pod
          relabel_configs:
            - source_labels: [__meta_kubernetes_namespace]
              regex: "{{ service_name }}"
              action: keep
            - source_labels: [__meta_kubernetes_pod_label_app]
              regex: "{{ service_name }}"
              action: keep
            - source_labels: [__meta_kubernetes_pod_label_component]
              regex: alertmanager
              action: keep
            - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_probe]
              regex: .*
              action: keep
            - source_labels: [__meta_kubernetes_pod_container_port_number]
              regex: "9093"
              action: keep
  recording_rules.yml: |
    {}
  rules: |
    {}
