# Prometheus Configuration for Pamsika WhatsApp Bot
# Production-ready monitoring setup with comprehensive metrics collection

global:
  scrape_interval: 15s
  evaluation_interval: 15s
  external_labels:
    monitor: 'pamsika-whatsapp-bot'
    environment: 'production'

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'
rule_files:
  - "alert_rules.yml"
  - "recording_rules.yml"

# Scrape configuration
scrape_configs:
  # Pamsika WhatsApp Bot application metrics
  - job_name: 'pamsika-bot'
    static_configs:
      - targets: ['pamsika-bot:3003']
    metrics_path: '/health'
    scrape_interval: 30s
    scrape_timeout: 10s
    params:
      format: ['prometheus']
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: pamsika-bot:3003

  # Node Exporter for system metrics
  - job_name: 'node-exporter'
    static_configs:
      - targets: ['node-exporter:9100']
    scrape_interval: 15s
    relabel_configs:
      - source_labels: [__address__]
        regex: '([^:]+):.+'
        target_label: instance
        replacement: '${1}'

  # Redis metrics
  - job_name: 'redis'
    static_configs:
      - targets: ['redis-exporter:9121']
    scrape_interval: 30s
    metrics_path: '/metrics'

  # PostgreSQL metrics
  - job_name: 'postgres'
    static_configs:
      - targets: ['postgres-exporter:9187']
    scrape_interval: 30s
    metrics_path: '/metrics'

  # Nginx metrics
  - job_name: 'nginx'
    static_configs:
      - targets: ['nginx-exporter:9113']
    scrape_interval: 30s
    metrics_path: '/metrics'

  # cAdvisor for container metrics
  - job_name: 'cadvisor'
    static_configs:
      - targets: ['cadvisor:8080']
    scrape_interval: 30s
    metrics_path: '/metrics'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: cadvisor:8080

  # Prometheus itself
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
    scrape_interval: 30s

  # Blackbox exporter for external monitoring
  - job_name: 'blackbox-http'
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:
        - https://pamsikaonline.com
        - https://test.pamsikaonline.com/api/health
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: blackbox-exporter:9115

  # SSL certificate monitoring
  - job_name: 'blackbox-ssl'
    metrics_path: /probe
    params:
      module: [ssl_expiry]
    static_configs:
      - targets:
        - pamsikaonline.com:443
        - test.pamsikaonline.com:443
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: blackbox-exporter:9115

  # Custom application metrics endpoint
  - job_name: 'pamsika-bot-metrics'
    static_configs:
      - targets: ['pamsika-bot:3003']
    metrics_path: '/metrics'
    scrape_interval: 15s
    scrape_timeout: 10s
    honor_labels: true
    relabel_configs:
      - source_labels: [__address__]
        target_label: service
        replacement: 'pamsika-whatsapp-bot'

  # Service discovery for dynamic targets (optional)
  # - job_name: 'consul-services'
  #   consul_sd_configs:
  #     - server: 'consul:8500'
  #       services: ['pamsika-bot', 'redis', 'postgres']
  #   relabel_configs:
  #     - source_labels: [__meta_consul_service]
  #       target_label: job
  #     - source_labels: [__meta_consul_node]
  #       target_label: instance

# Remote write configuration (for long-term storage)
# remote_write:
#   - url: "https://prometheus-remote-write.example.com/api/v1/write"
#     basic_auth:
#       username: "your-username"
#       password: "your-password"
#     write_relabel_configs:
#       - source_labels: [__name__]
#         regex: 'pamsika_.*'
#         action: keep

# Remote read configuration (for long-term storage)
# remote_read:
#   - url: "https://prometheus-remote-read.example.com/api/v1/read"
#     basic_auth:
#       username: "your-username"
#       password: "your-password"

# Storage configuration
storage:
  tsdb:
    path: /prometheus
    retention.time: 30d
    retention.size: 10GB
    wal-compression: true
