Skip to main content

Prometheus Metrics

Server-side metrics collection for monitoring and visualization with Prometheus and Grafana.

Overview

The metrics system provides:

  • Custom metric types - Counters, Gauges, Histograms
  • Pre-defined FiveM metrics - Player counts, RPC stats, DB operations
  • HTTP endpoint - Prometheus scrape target on configurable port
  • Live map integration - Player positions for real-time visualization

Architecture

Configuration

Set the metrics port via convar:

# server.cfg
set metrics_port "9100"

Built-in Metrics

MetricTypeDescription
fivem_players_onlineGaugeCurrent player count
fivem_player_connections_totalCounterTotal connections
fivem_player_disconnections_totalCounterTotal disconnections
fivem_module_statusGaugeModule running state (0/1)
fivem_module_startup_secondsHistogramModule startup time
fivem_rpc_calls_totalCounterRPC call count by direction
fivem_rpc_duration_secondsHistogramRPC latency
fivem_db_operations_totalCounterDatabase operations
fivem_server_uptime_secondsGaugeServer uptime
fivem_player_position_xGaugePlayer X coordinate (per-player)
fivem_player_position_yGaugePlayer Y coordinate (per-player)
fivem_player_position_zGaugePlayer Z coordinate (per-player)

Custom Metrics

Create custom metrics for your modules:

import { createCounter, createGauge, createHistogram } from "@core/metrics";

const itemsPurchased = createCounter({
name: "shop_items_purchased_total",
help: "Total items purchased",
labels: ["item_type"],
});

const accountBalance = createGauge({
name: "banking_account_balance",
help: "Current account balance",
labels: ["account_id"],
});

const rpcLatency = createHistogram({
name: "custom_rpc_duration_seconds",
help: "Custom RPC call latency",
labels: ["method"],
buckets: [0.01, 0.05, 0.1, 0.5, 1, 5],
});

// Usage
itemsPurchased.inc({ item_type: "weapon" });
accountBalance.set({ account_id: "123" }, 50000);
rpcLatency.observe({ method: "fetchData" }, 0.045);

Live Map

The metrics system exports player positions for the live map visualization at http://localhost:3002.

Positions are updated every 5 seconds and include heading data for directional markers.

Grafana Dashboards

Pre-configured dashboards are available in infra/grafana/provisioning/dashboards/:

  • Server overview (players, uptime, module status)
  • RPC performance (latency, error rates)
  • Database metrics (operations, duration)

See Live Map Guide for map setup instructions.