apiVersion: v1
kind: ConfigMap
metadata:
  name: k8sdc-prometheus
  namespace: k8sdc-system
  #namespace: {{ .namespace }}
  labels:
    app: k8sdc-prometheus
    heritage: k8sdc
data:
  prometheus.yml: |
    # Mostly sourced from https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml
    global:
      scrape_interval:     15s
      evaluation_interval: 15s

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

    scrape_configs:
      - job_name: 'prometheus'
        scrape_interval: 5s
        static_configs:
          - targets: ['localhost:9090']

      - job_name: 'etcd'
        static_configs:
          - targets:
            - 192.168.1.210:2379
            - 192.168.1.211:2379
            - 192.168.1.212:2379
            - 192.168.1.213:2379
            - 192.168.1.214:2379
            - 192.168.1.215:2379
            - 192.168.1.216:2379
            - 192.168.1.217:2379

      - job_name: 'kubernetes-apiserver'
        tls_config:
          ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
        kubernetes_sd_configs:
          - api_servers:
            - 'https://kubernetes.default.svc'
            in_cluster: true
        relabel_configs:
          - source_labels: [__meta_kubernetes_role]
            action: keep
            regex: (apiserver)
          - source_labels: [__meta_kubernetes_role]
            action: replace
            target_label: kubernetes_role
          # - source_labels: [__meta_kubernetes_role]
          #   target_label: job
          #   replacement: kubernetes-$1
          # - action: labelmap
          #   regex: __meta_kubernetes_node_label_(.+)


      # Use insecure Kubelet port
      - job_name: 'kubernetes-nodes'
        scheme: http
        tls_config:
          ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
        kubernetes_sd_configs:
          - api_servers:
            - 'https://kubernetes.default.svc'
            in_cluster: true
        relabel_configs:
          - source_labels: [__meta_kubernetes_role]
            action: keep
            regex: (node)
          - action: labelmap
            regex: __meta_kubernetes_node_label_(.+)
          - source_labels: [__meta_kubernetes_role]
            action: replace
            target_label: kubernetes_role
          - source_labels: [__address__]
            action: replace
            target_label: kubernetes_node_address
          - source_labels: [__address__]
            action: replace
            target_label: __address__
            regex: ([\d.]*).*
            replacement: $1:10255
            
  

          



      # - job_name: 'kubernetes-service-endpoints'
      #   kubernetes_sd_configs:
      #     - api_servers:
      #       - 'https://kubernetes.default.svc'
      #       in_cluster: true
      #   relabel_configs:
      #     - source_labels: [__meta_kubernetes_role, __meta_kubernetes_service_annotation_prometheus_io_scrape]
      #       action: keep
      #       regex: endpoint;true
      #     - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
      #       action: replace
      #       target_label: __scheme__
      #       regex: (https?)
      #     - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
      #       action: replace
      #       target_label: __metrics_path__
      #       regex: (.+)
      #     - 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_(.+)
      #     - source_labels: [__meta_kubernetes_role]
      #       action: replace
      #       target_label: kubernetes_role
      #     - source_labels: [__meta_kubernetes_service_namespace]
      #       action: replace
      #       target_label: kubernetes_namespace
      #     - source_labels: [__meta_kubernetes_service_name]
      #       action: replace
      #       target_label: kubernetes_name

      # - job_name: 'kubernetes-pods'
      #   kubernetes_sd_configs:
      #     - api_servers:
      #       - 'https://kubernetes.default.svc'
      #       in_cluster: true
      #   relabel_configs:
      #     - source_labels: [__meta_kubernetes_role, __meta_kubernetes_pod_annotation_prometheus_io_scrape]
      #       action: keep
      #       regex: pod;true
      #     - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
      #       action: replace
      #       regex: (.+):(?:\d+);(\d+)
      #       replacement: ${1}:${2}
      #       target_label: __address__
      #     - action: labelmap
      #       regex: __meta_kubernetes_pod_label_(.+)
      #     - source_labels: [__meta_kubernetes_pod_namespace]
      #       action: replace
      #       target_label: kubernetes_namespace
      #     - source_labels: [__meta_kubernetes_pod_name]
      #       action: replace
      #       target_label: kubernetes_pod_name