# Source: tidb-cluster/templates/monitor-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: external-config
  labels:
    app.kubernetes.io/name: tidb-cluster
    app.kubernetes.io/instance: test
    app.kubernetes.io/component: monitor
data:
  prometheus-config: |-
    global:
      scrape_interval: 15s
      evaluation_interval: 15s
      external_labels:
        prometheus_replica: $(NAMESPACE)_$(POD_NAME)
    scrape_configs:
    - job_name: tidb-cluster-basic-pd
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: pd
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_instance,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $1.$2-pd-peer.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: tidb-cluster-basic-tidb
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: tidb
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_instance,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $1.$2-tidb-peer.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: tidb-cluster-basic-tikv
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: tikv
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_instance,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $1.$2-tikv-peer.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: tidb-cluster-basic-tiflash
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: tiflash
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_instance,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $1.$2-tiflash-peer.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: tidb-cluster-basic-tiflash-proxy
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: tiflash
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_instance,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_tiflash_proxy_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $1.$2-tiflash-peer.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: tidb-cluster-basic-pump
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: pump
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_instance,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $1.$2-pump.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: tidb-cluster-basic-drainer
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: drainer
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_name,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $1.$2.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: tidb-cluster-basic-ticdc
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: ticdc
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_instance,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $1.$2-ticdc-peer.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: tidb-cluster-basic-importer
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: importer
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_instance,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $1.$2-importer.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: tidb-cluster-basic-lightning
      honor_labels: true
      scrape_interval: 15s
      scheme: http
      kubernetes_sd_configs:
      - api_server: null
        role: pod
        namespaces:
          names:
          - tidb-cluster
      tls_config:
        insecure_skip_verify: true
      relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        regex: basic
        action: keep
      - source_labels: [__meta_kubernetes_namespace]
        regex: tidb-cluster
        action: keep
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        regex: tidb-lightning
        action: keep
      - source_labels: [__meta_kubernetes_pod_name, __meta_kubernetes_pod_label_app_kubernetes_io_name,
          __meta_kubernetes_namespace, __meta_kubernetes_pod_annotation_prometheus_io_port]
        regex: (.+);(.+);(.+);(.+)
        target_label: __address__
        replacement: $2.$3:$4
        action: replace
      - source_labels: [__meta_kubernetes_namespace]
        target_label: kubernetes_namespace
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
        target_label: cluster
        action: replace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: instance
        action: replace
      - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
        target_label: component
        action: replace
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app_kubernetes_io_instance]
        separator: '-'
        target_label: tidb_cluster
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        regex: (.+)
        target_label: __metrics_path__
        action: replace
    - job_name: prometheus-anomaly-detector
      honor_labels: true
      scrape_interval: 15s
      scrape_timeout: 10s
      metrics_path: /metrics
      scheme: http
      static_configs:
        - targets: ['prometheus-anomaly-detector.tidb-cluster.svc.cluster.local:8080']
          labels:
            group: 'anomaly-detection'
    rule_files:
          - '/prometheus-rules/rules/*.rules.yml'
          - '/prometheus-external-rules/*.rules.yml'