apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-conf
  namespace: observability
data:
  prometheus.yml: |
    global:
      scrape_interval: 5s # By default, scrape targets every 5 seconds.
      evaluation_interval: 15s

      # Attach these labels to any time series or alerts when communicating with
      # external systems (federation, remote storage, Alertmanager).
      external_labels:
        monitor: "minikube-test-server"

      # Load and evaluate rules in this file every 'evaluation_interval' seconds.
    rule_files:
      # - "alert.rules"
      # - "first.rules"
      # - "second.rules"

    # A scrape configuration containing exactly one endpoint to scrape:
    scrape_configs:
      # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

      - job_name: "redis-cache-service"
        metrics_path: /metrics
        static_configs:
          - targets: ["observ-redis-cache-service:9121"]
            labels:
              namespace: "observ"
              env: "minikube"
              region: "minikube"
              service: "redis-cache-service"

      - job_name: "pgsql-exporter-service"
        metrics_path: /metrics
        static_configs:
          - targets: ["observ-postgres:9187"]
            labels:
              namespace: "observ"
              env: "minikube"
              region: "minikube"
              service: "pgsql-db"

      - job_name: prometheus-minikube-server
        static_configs:
          - targets: ["localhost:9090"]

  alert.rules: |
    groups:
    - name: example
      rules:

      # Alert for any instance that is unreachable for >2 minutes.
      - alert: service_down
        expr: up == 0
        for: 2m
        labels:
          severity: page
        annotations:
          summary: "Instance {{ $labels.instance }} down"
          description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 2 minutes."

      - alert: high_load
        expr: node_load1 > 0.5
        for: 2m
        labels:
          severity: page
        annotations:
          summary: "Instance {{ $labels.instance }} under high load"
          description: "{{ $labels.instance }} of job {{ $labels.job }} is under high load."
