apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    application: prometheus
  name: prometheus-conf
  namespace: kube-system
data:
  prometheus.yml: |-
    global:
      scrape_interval: 15s
      external_labels:
        monitor: 'skipper-ingress'
    scrape_configs:
    # scrape from kube-apiserver pods
    - job_name: 'kubernetes-apiservers'
      scheme: https
      tls_config:
        insecure_skip_verify: true
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      kubernetes_sd_configs:
      - role: pod
        namespaces:
          names:
            - kube-system
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_application, __meta_kubernetes_pod_container_port_number]
        action: keep
        regex: kube-apiserver;443
      - action: replace
        source_labels: ['__meta_kubernetes_pod_label_application']
        target_label: application
    - job_name: 'teapot-admission-controller'
      scheme: https
      tls_config:
        insecure_skip_verify: true
      kubernetes_sd_configs:
      - role: pod
        namespaces:
          names:
            - kube-system
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_application, __meta_kubernetes_pod_container_port_number]
        action: keep
        regex: kube-apiserver;8085
      - action: replace
        source_labels: ['__meta_kubernetes_pod_label_application']
        target_label: application
    - job_name: 'kube-state-metrics'
      scheme: http
      honor_labels: true
      kubernetes_sd_configs:
      - role: endpoints
        namespaces:
          names:
            - kube-system
      relabel_configs:
      - source_labels: [__meta_kubernetes_endpoints_name]
        action: keep
        regex: kube-state-metrics
      metric_relabel_configs:
      - action: replace
        source_labels: [pod]
        target_label: pod_name
      - action: replace
        source_labels: [container]
        target_label: container_name
      - action: replace
        source_labels: [node]
        target_label: node_name
      - action: labeldrop
        regex: "^(pod|node|container)$"
    - job_name: 'etcd-servers'
      scheme: http
      dns_sd_configs:
      - names:
        - "{{ with $hostPort := splitHostPort .ConfigItems.etcd_endpoints }}{{ .Host }}{{ end }}"
        type: "A"
        port: 2381
    - job_name: 'kubernetes-service-endpoints'
      scheme: http
      kubernetes_sd_configs:
      - role: endpoints
        namespaces:
          names:
            - kube-system
      relabel_configs:
      # Look for the Prometheus annotations and scrape based on those
      - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
        action: keep
        regex: 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
      # Add pod information
      - action: replace
        source_labels: ['__meta_kubernetes_pod_ip']
        target_label: pod_ip
      - action: replace
        source_labels: ['__meta_kubernetes_namespace']
        target_label: namespace
      - action: replace
        source_labels: ['__meta_kubernetes_pod_label_application']
        target_label: application
      - action: replace
        source_labels: ['__meta_kubernetes_pod_name']
        target_label: pod_name
      - action: replace
        source_labels: ['__meta_kubernetes_pod_node_name']
        target_label: node_name
    - job_name: 'cadvisor'
      scheme: http
      honor_labels: true
      kubernetes_sd_configs:
      - role: endpoints
        namespaces:
          names:
            - kube-system
      relabel_configs:
      - source_labels: [__meta_kubernetes_endpoints_name]
        action: keep
        regex: cadvisor
      - action: replace
        source_labels: ['__meta_kubernetes_pod_node_name']
        target_label: node_name
      metric_relabel_configs:
      - action: replace
        source_labels: ['container_label_application']
        target_label: application
      - action: replace
        source_labels: ['container_label_io_kubernetes_container_name']
        target_label: container_name
      - action: replace
        source_labels: ['container_label_io_kubernetes_pod_name']
        target_label: pod_name
      - action: replace
        source_labels: ['container_label_io_kubernetes_pod_namespace']
        target_label: namespace
      - action: replace
        source_labels: ['container_label_io_kubernetes_pod_uid']
        target_label: uid
      - source_labels: [__name__]
        action: keep
        regex: '(container_cpu_cfs_throttled_seconds_total|container_cpu_usage_seconds_total|container_memory_working_set_bytes|container_memory_rss|container_memory_cache|container_network_receive_bytes_total|container_network_transmit_bytes_total|container_fs_usage_bytes|container_fs_limit_bytes|container_fs_reads_bytes_total|container_fs_writes_bytes_total|container_threads|container_threads_max)'
    - job_name: 'kubelet-metrics'
      scheme: https
      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:
      - role: node
      relabel_configs:
      - source_labels: [__meta_kubernetes_node_address_Hostname]
        target_label: __address__
        regex: (.*)
        replacement: $1:10250
      metric_relabel_configs:
       - source_labels: [ __name__ ]
         regex: 'reflector.*'
         action: drop
