# Prometheus metrics configuration for tokenization system

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  # Tokenization Service Metrics
  - job_name: 'tokenization-service'
    static_configs:
      - targets: ['localhost:9091']
    metrics_path: '/metrics'
    scrape_interval: 10s

  # FireFly Metrics
  - job_name: 'firefly-tokenization'
    static_configs:
      - targets: ['localhost:9092']
    metrics_path: '/metrics'
    scrape_interval: 15s

  # Cacti Metrics
  - job_name: 'cacti-bridge'
    static_configs:
      - targets: ['localhost:9093']
    metrics_path: '/metrics'
    scrape_interval: 15s

  # Fabric Chaincode Metrics
  - job_name: 'fabric-chaincode'
    static_configs:
      - targets: ['localhost:9094']
    metrics_path: '/metrics'
    scrape_interval: 30s

  # Besu Contract Metrics
  - job_name: 'besu-contracts'
    static_configs:
      - targets: ['localhost:9095']
    metrics_path: '/metrics'
    scrape_interval: 15s

# Recording rules for tokenization metrics
groups:
  - name: tokenization
    interval: 30s
    rules:
      # Tokenization rate
      - record: tokenization:rate:1m
        expr: rate(tokenization_operations_total[1m])

      # Reserve ratio
      - record: tokenization:reserve:ratio
        expr: tokenization_reserve_backed_amount / tokenization_reserve_total_amount

      # Success rate
      - record: tokenization:success:rate:1h
        expr: |
          sum(rate(tokenization_operations_total{status="success"}[1h])) /
          sum(rate(tokenization_operations_total[1h]))

      # Average settlement time
      - record: tokenization:settlement:time:avg
        expr: histogram_quantile(0.5, tokenization_settlement_duration_seconds_bucket)

      # P95 settlement time
      - record: tokenization:settlement:time:p95
        expr: histogram_quantile(0.95, tokenization_settlement_duration_seconds_bucket)

      # P99 settlement time
      - record: tokenization:settlement:time:p99
        expr: histogram_quantile(0.99, tokenization_settlement_duration_seconds_bucket)

      # Active tokenized assets
      - record: tokenization:assets:active
        expr: tokenization_assets_total{status="active"}

      # Total supply
      - record: tokenization:supply:total
        expr: sum(tokenization_token_total_supply)

      # Backed amount
      - record: tokenization:backed:amount
        expr: sum(tokenization_reserve_backed_amount)

      # Reserve health
      - record: tokenization:reserve:health
        expr: |
          (tokenization_reserve_backed_amount / tokenization_reserve_total_amount) >= 1.0
