---
#==============================================================#
# File      :   prometheus.yml
# Ctime     :   2026-01-22
# Desc      :   VictoriaMetrics Configuration File
# Path      :   /infra/prometheus.yml
# License   :   Apache-2.0 @ https://pigsty.io/docs/about/license/
# Copyright :   2018-2026  Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
# VictoriaMetrics is fully compatible with Prometheus config
# https://docs.victoriametrics.com/single-server-victoriametrics/#how-to-scrape-prometheus-exporters-such-as-node-exporter
#--------------------------------------------------------------#

#--------------------------------------------------------------#
# Globals
#--------------------------------------------------------------#
global:
  scrape_interval: {{ vmetrics_scrape_interval }}
  scrape_timeout:  {{ vmetrics_scrape_timeout }}


#--------------------------------------------------------------#
# Targets Definition
#--------------------------------------------------------------#
# https://docs.victoriametrics.com/sd_configs/
scrape_configs:

  #--------------------------------------------------------------#
  # job: ping
  # blackbox exporter metrics
  #--------------------------------------------------------------#
  - job_name: ping
    metrics_path: /probe
    params: {module: [icmp]}
    file_sd_configs:
      - files: [ /infra/targets/ping/*.yml ]
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115

  #--------------------------------------------------------------#
  # job: infra
  # targets: vmetrics | grafana | altermanager | vlogs | nginx
  # labels: [ip, instance, type]
  # path: targets/infra/<ip>.yml
  #--------------------------------------------------------------#
  - job_name: infra
    metrics_path: /metrics
    file_sd_configs:
      - files: [ /infra/targets/infra/*.yml ]

  #--------------------------------------------------------------#
  # job: node
  # node_exporter, haproxy, docker, vector
  # labels: [cls, ins, ip, instance]
  # path: targets/node/<ip>.yml
  #--------------------------------------------------------------#
  - job_name: node
    metrics_path: {{ exporter_metrics_path }}
    file_sd_configs:
      - files: [ /infra/targets/node/*.yml ]

  #--------------------------------------------------------------#
  # job: docker
  # docker daemon
  # labels: [cls, ins, ip, instance]
  # path: targets/docker/<ip>.yml
  #--------------------------------------------------------------#
  - job_name: docker
    metrics_path: /metrics
    file_sd_configs:
      - files: [ /infra/targets/docker/*.yml ]
    relabel_configs: # relabel docker metrics job to node
      - source_labels: [job]
        target_label: job
        replacement: 'node'

  #--------------------------------------------------------------#
  # job: etcd
  # labels: [cls, ins, ip, instance]
  # path: targets/etcd/<etcd_instance>.yml
  #--------------------------------------------------------------#
  - job_name: etcd
    metrics_path: /metrics
    file_sd_configs:
      - files: [ /infra/targets/etcd/*.yml ]
    scheme: https
    tls_config:
      ca_file:   /etc/pki/ca.crt
      cert_file: /etc/pki/infra.crt
      key_file:  /etc/pki/infra.key

  #--------------------------------------------------------------#
  # job: minio
  # labels: [cls, ins, ip, instance]
  # path: targets/minio/<minio_instance>.yml
  #--------------------------------------------------------------#
  - job_name: minio
    metrics_path: /minio/v2/metrics/cluster
    file_sd_configs:
      - files: [ /infra/targets/minio/*.yml ]
    scheme: {% if minio_https|default(true)|bool %}https{% else %}http{% endif %}

{% if minio_https|default(true)|bool %}
    tls_config:
      ca_file:   /etc/pki/ca.crt
      cert_file: /etc/pki/infra.crt
      key_file:  /etc/pki/infra.key
{% endif %}

  #--------------------------------------------------------------#
  # job: pgsql
  # pg_exporter | pgbouncer_exporter | patroni (if ssl disabled)
  # labels: [cls, ins, ip, instance]
  # path: targets/pgsql/<pg_instance>.yml
  #--------------------------------------------------------------#
  - job_name: pgsql
    metrics_path: {{ exporter_metrics_path }}
    file_sd_configs:
      - files: [ /infra/targets/pgsql/*.yml ]

{% if patroni_ssl_enabled|bool %}
  #--------------------------------------------------------------#
  # job: patroni -> pgsql
  # labels: [cls, ins, ip, instance]
  # path: targets/patroni/<pg_instance>.yml
  #--------------------------------------------------------------#
  - job_name: pgsql-patroni     # this job is used when `patroni_ssl_enabled`
    honor_labels: true          # job name will be overwrite to 'pgsql' instead
    metrics_path: /metrics      # patroni can not customize exporter metrics
    scheme: https
    tls_config:
      ca_file: /etc/pki/ca.crt
    file_sd_configs:
      - files: [ /infra/targets/patroni/*.yml ]
{% endif %}

  #--------------------------------------------------------------#
  # job: pgrds
  # pg_exporter on local
  # labels: [cls, ins, ip, job]
  # path: targets/pgrds/<pg_cluster>.yml
  #--------------------------------------------------------------#
  - job_name: pgrds
    metrics_path: {{ exporter_metrics_path }}
    file_sd_configs:
      - files: [ /infra/targets/pgrds/*.yml ]

  #--------------------------------------------------------------#
  # job: redis
  # multiple redis targets from redis_exporter @ target node
  # labels: [cls, ip, ins, instance]
  # path: targets/redis/<redis_node>.yml
  #--------------------------------------------------------------#
  - job_name: redis
    metrics_path: /scrape
    file_sd_configs:
      - files: [ /infra/targets/redis/*.yml ]
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        regex: ^redis://(.*):(\d+)$
        replacement: $1:$2
        target_label: instance
      - source_labels: [__param_target]
        regex: ^redis://(.*):(\d+)$
        replacement: $1
        target_label: ip
      # scrape redis_exporter on target node
      - source_labels: [__param_target]
        regex: ^redis://(.*):\d+$
        replacement: $1:{{ redis_exporter_port }}
        target_label: __address__

  #--------------------------------------------------------------#
  # job: mysql
  # labels: [cls, ins, ip, instance]
  # path: targets/mysql/<mysql_instance>.yml
  #--------------------------------------------------------------#
  - job_name: mysql
    metrics_path: {{ exporter_metrics_path }}
    file_sd_configs:
      - files: [ /infra/targets/mysql/*.yml ]

  #--------------------------------------------------------------#
  # job: mongo (ferretdb)
  # labels: [cls, ins, ip, instance]
  # path: targets/mongo/<mongo_instance>.yml
  #--------------------------------------------------------------#
  - job_name: mongo
    metrics_path: /debug/metrics
    file_sd_configs:
      - files: [ /infra/targets/mongo/*.yml ]

  #--------------------------------------------------------------#
  # job: kafka
  # labels: [cls, ins, ip, instance]
  # path: targets/kafka/<kafka_instance>.yml
  #--------------------------------------------------------------#
  - job_name: kafka
    metrics_path: {{ exporter_metrics_path }}
    file_sd_configs:
      - files: [ /infra/targets/kafka/*.yml ]

  #--------------------------------------------------------------#
  # job: juice
  # juicefs metrics
  # labels: [cls, ins, ip, instance]
  # path: targets/juice/<ip>.yml
  #--------------------------------------------------------------#
  - job_name: juice
    metrics_path: /metrics
    file_sd_configs:
      - files: [ /infra/targets/juice/*.yml ]

...