apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: enmasse
  name: prometheus-config
data:
  prometheus.yml: |
    global:
      evaluation_interval: 60s
      scrape_interval: 60s
    rule_files:
      - 'rules.yaml'
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          - alertmanager:9093
    scrape_configs:
      - job_name: 'artemis_pod_job'
        kubernetes_sd_configs:
          - role: pod
            namespaces:
              names:
                - amq-online-infra
        relabel_configs:
          - action: keep
            source_labels: [__meta_kubernetes_pod_container_port_name]
            regex: artemismetrics.*
          - action: replace
            source_labels: [__meta_kubernetes_pod_name]
            target_label: kubernetes_pod_name
      - job_name: 'router_pod_job'
        kubernetes_sd_configs:
          - role: pod
            namespaces:
              names:
                - amq-online-infra
        relabel_configs:
          - action: keep
            source_labels: [__meta_kubernetes_pod_container_port_name]
            regex: routermetrics.*
          - action: replace
            source_labels: [__meta_kubernetes_pod_name]
            target_label: kubernetes_pod_name
      - job_name: component-health
        kubernetes_sd_configs:
          - role: service
            namespaces:
              names:
                - amq-online-infra
        metrics_path: "/metrics"
        relabel_configs:
        - action: keep
          regex: health.*
          source_labels: [__meta_kubernetes_service_port_name]
        - action: replace
          source_labels: [__meta_kubernetes_service_name]
          target_label: kubernetes_pod_name
      - job_name: 'kube-metrics'
        kubernetes_sd_configs:
          - role: pod
            namespaces:
              names:
                - amq-online-infra
        relabel_configs:
        - action: keep
          regex: kube-metrics.*
          source_labels: [__meta_kubernetes_pod_container_port_name]
        - action: labelmap
          regex: __meta_kubernetes_pod_label_(.+)
  rules.yaml: |
    groups:
    - name: ComponentHealth
      rules:
      - alert: Component_Health
        annotations:
          description: '{{ $labels.summary }}'
          value: "{{ $value }}"
          severity: warning
        expr: health == 1
        for: 10s
      - alert: Component_Health
        annotations:
          description: '{{ $labels.summary }}'
          value: "{{ $value }}"
          severity: critical
        expr: health == 2
        for: 10s
      - alert: Component_Health
        annotations:
          description: '{{ $labels.summary }}'
          value: "{{ $value }}"
          severity: unknown
        expr: health == 3
        for: 10s
      - alert: Component_Ping
        annotations:
          description: "Component unreachable"
          value: "{{ $value }}"
          severity: critical
        expr: up != 1
        for: 10s
      - alert: Address_Space_Health
        annotations:
          description: '{{ $labels.summary }}'
          value: "{{ $value }}"
          severity: warning
        expr: address_spaces_ready == 0
        for: 60s
      - alert: Terminating_Pods
        annotations:
          description: '{{ $labels.pod }}'
          value: "{{ $value }}"
          severity: warning
        expr: kube_pod_container_status_terminated == 1
        for: 10s
      - alert: Restarting Pods
        annotations:
          description: '{{ $labels.pod }}'
          value: "{{ $value }}"
          severity: warning
        expr: rate(kube_pod_container_status_restarts_total[10m]) * 600 > 5
        for: 10s
