# Useful examples on how to configure Prometheus
# * https://www.weave.works/prometheus-and-kubernetes-monitoring-your-applications/
# * https://grafana.net/dashboards/162
# * https://raw.githubusercontent.com/prometheus/prometheus/master/documentation/examples/prometheus-kubernetes.yml
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-configmap
  namespace: monitoring-sock-shop
data:
  prometheus.yml: |
    global:
      scrape_interval: 15s
    rule_files:
      - "/etc/prometheus-rules/alert.rules"
    scrape_configs:
      - job_name: kubernetes-service-endpoints
        kubernetes_sd_configs:
          - role: endpoints
        tls_config:
          ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
        relabel_configs:
          - source_labels:
              - __meta_kubernetes_service_label_component
            regex: apiserver
            action: replace
            target_label: __scheme__
            replacement: https
          - source_labels:
              - __meta_kubernetes_service_label_kubernetes_io_cluster_service
            action: drop
            regex: 'true'
          - source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_scrape
            action: drop
            regex: 'false'
          - source_labels:
              - __meta_kubernetes_pod_container_port_name
            action: drop
            regex: .*-noscrape
          - source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_scheme
            action: replace
            target_label: __scheme__
            regex: ^(https?)$
            replacement: $1
          - source_labels:
              - __meta_kubernetes_service_annotation_prometheus_io_path
            action: replace
            target_label: __metrics_path__
            regex: ^(.+)$
            replacement: $1
          - source_labels:
              - __address__
              - __meta_kubernetes_service_annotation_prometheus_io_port
            action: replace
            target_label: __address__
            regex: '^(.+)(?::\d+);(\d+)$'
            replacement: '$1:$2'
          - action: labelmap
            regex: ^__meta_kubernetes_service_label_(.+)$
            replacement: $1
          - source_labels:
              - __meta_kubernetes_namespace
              - __meta_kubernetes_service_name
            separator: /
            target_label: job
      - job_name: kubernetes-pods
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - source_labels:
              - __meta_kubernetes_pod_annotation_prometheus_io_scrape
            action: keep
            regex: 'true'
          - source_labels:
              - __meta_kubernetes_namespace
              - __meta_kubernetes_pod_label_name
            separator: /
            target_label: job
          - source_labels:
              - __meta_kubernetes_pod_node_name
            target_label: node
      - job_name: kubernetes-nodes
        kubernetes_sd_configs:
          - role: node
        tls_config:
          insecure_skip_verify: true
        bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
        relabel_configs:
          - target_label: __scheme__
            replacement: https
          - source_labels:
              - __meta_kubernetes_node_label_kubernetes_io_hostname
            target_label: instance
      - job_name: weave
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - source_labels:
              - __meta_kubernetes_namespace
              - __meta_kubernetes_pod_label_name
            action: keep
            regex: ^kube-system;weave-net$
          - source_labels:
              - __meta_kubernetes_pod_container_name
              - __address__
            action: replace
            target_label: __address__
            regex: '^weave;(.+?)(?::\d+)?$'
            replacement: '$1:6782'
          - source_labels:
              - __meta_kubernetes_pod_container_name
              - __address__
            action: replace
            target_label: __address__
            regex: '^weave-npc;(.+?)(?::\d+)?$'
            replacement: '$1:6781'
          - source_labels:
              - __meta_kubernetes_pod_container_name
            action: replace
            target_label: job
