# Prometheus Community JSON Exporter Configuration Example
# File: examples/json_exporter.example.yml
#
# Use this configuration to map KoalaSync admin health metrics (JSON)
# to native Prometheus metrics.
#
# Usage:
# 1. Rename this file to json_exporter.yml
# 2. Replace "YOUR_ADMIN_METRICS_TOKEN" with your actual ADMIN_METRICS_TOKEN env value
# 3. Mount it to the json-exporter docker container: /config.yml

modules:
  koalasync:
    http_client_config:
      bearer_token: "YOUR_ADMIN_METRICS_TOKEN"
    metrics:
      - name: koalasync_uptime_seconds
        path: '{.uptime}'
        help: "Uptime of the KoalaSync relay server in seconds"

      - name: koalasync_rooms
        path: '{.rooms}'
        help: "Total active rooms"

      - name: koalasync_connections
        path: '{.connections}'
        help: "Total active socket connections (sockets)"

      - name: koalasync_peers
        path: '{.peers}'
        help: "Total connected peers across all rooms"

      - name: koalasync_rooms_with_lobby
        path: '{.roomsWithLobby}'
        help: "Number of rooms waiting in an episode lobby"

      - name: koalasync_avg_peers_per_room
        path: '{.avgPeersPerRoom}'
        help: "Average number of peers per room"

      - name: koalasync_max_peers_in_room
        path: '{.maxPeersInRoom}'
        help: "Maximum number of peers in a single room"

      - name: koalasync_memory_rss_bytes
        path: '{.memory.rss}'
        help: "Resident Set Size (RSS) memory usage in bytes"

      - name: koalasync_memory_heap_used_bytes
        path: '{.memory.heapUsed}'
        help: "V8 engine heap used in bytes"

      - name: koalasync_memory_heap_total_bytes
        path: '{.memory.heapTotal}'
        help: "V8 engine heap total in bytes"

      # Rate limiter tracking — unique clients currently in each tracking window
      # (not rate-limit denials; these include legitimate traffic too)

      - name: koalasync_rate_limit_connections
        path: '{.rateLimits.trackedClients.connections}'
        help: "Unique clients tracked in the connection rate limiter window"

      - name: koalasync_rate_limit_events
        path: '{.rateLimits.trackedClients.events}'
        help: "Unique sockets tracked in the event rate limiter window"

      - name: koalasync_rate_limit_health
        path: '{.rateLimits.trackedClients.health}'
        help: "Unique IPs tracked in the health endpoint rate limiter window"

      - name: koalasync_rate_limit_admin_metrics_auth
        path: '{.rateLimits.trackedClients.adminMetricsAuth}'
        help: "Unique IPs tracked in the admin metrics auth rate limiter window"

      - name: koalasync_rate_limit_auth_failures
        path: '{.rateLimits.trackedClients.authFailures}'
        help: "Unique IPs tracked in the authentication failures cache"

      - name: koalasync_rate_limit_room_list
        path: '{.rateLimits.trackedClients.roomList}'
        help: "Unique sockets in the room list cooldown cache"

      # Actual rate-limit denials — incremented only when a 429 is served

      - name: koalasync_rate_limit_denied_connections
        path: '{.rateLimits.denied.connections}'
        help: "Total connection attempts denied by rate limiter"

      - name: koalasync_rate_limit_denied_events
        path: '{.rateLimits.denied.events}'
        help: "Total socket events denied by rate limiter"

      - name: koalasync_rate_limit_denied_health
        path: '{.rateLimits.denied.health}'
        help: "Total health endpoint requests denied by rate limiter"

      - name: koalasync_rate_limit_denied_admin_metrics_auth
        path: '{.rateLimits.denied.adminMetricsAuth}'
        help: "Total admin metrics auth attempts denied by rate limiter"

      - name: koalasync_rate_limit_denied_room_list
        path: '{.rateLimits.denied.roomList}'
        help: "Total room list refresh requests denied by rate limiter"
