# Prometheus Configuration for Mercury Device Middleware - Phase 4.1
# Production monitoring configuration for reversal system observability

global:
  scrape_interval: 15s  # Default scrape interval
  evaluation_interval: 15s  # Evaluate rules every 15 seconds
  external_labels:
    cluster: 'mercury-device-middlelayer'
    environment: 'production'

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

# Rule files specify a list of globs (optional)
rule_files:
  - "reversal_alert_rules.yml"

# Scrape configuration - what endpoints to monitor
scrape_configs:
  # Mercury Device Middleware Application
  - job_name: 'mercury-device-middleware'
    static_configs:
      - targets: ['localhost:4000']  # Phoenix application
    metrics_path: '/monitoring/metrics'
    scrape_interval: 10s  # More frequent for real-time monitoring
    scrape_timeout: 5s
    
    # Additional labels for identification
    labels:
      environment: 'production'
      service: 'mercury-middleware'
      component: 'reversal-system'
    
    # Health check and monitoring metadata
    params:
      format: ['prometheus']
    
    # Metric relabeling for better organization
    metric_relabel_configs:
      # Add application labels
      - source_labels: [__name__]
        regex: 'reversal_.*'
        target_label: 'application'
        replacement: 'mercury-device-middlelayer'
      
      # Add component label
      - source_labels: [__name__]
        regex: 'reversal_.*'
        target_label: 'component'
        replacement: 'reversal-system'
      
      # Add version label
      - source_labels: [__name__]
        regex: 'reversal_.*'
        target_label: 'version'
        replacement: 'phase4.1'
    
  # System metrics (node_exporter)
  - job_name: 'node-exporter'
    static_configs:
      - targets: ['localhost:9100']
    scrape_interval: 30s

  # Database metrics (postgres_exporter) 
  - job_name: 'postgres-exporter'
    static_configs:
      - targets: ['localhost:9187']
    scrape_interval: 30s
    
  # Prometheus self-monitoring
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
    scrape_interval: 30s

# Remote write configuration (optional - for external storage)
# remote_write:
#   - url: "https://your-remote-storage-endpoint/api/v1/write"
#     basic_auth:
#       username: "your-username"
#       password: "your-password"

# Storage configuration
storage:
  tsdb:
    retention.time: 30d  # Keep 30 days of data
    retention.size: 50GB  # Maximum 50GB storage
    path: /var/lib/prometheus