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
| Metric | Type | Description |
|---|---|---|
fivem_players_online | Gauge | Current player count |
fivem_player_connections_total | Counter | Total connections |
fivem_player_disconnections_total | Counter | Total disconnections |
fivem_module_status | Gauge | Module running state (0/1) |
fivem_module_startup_seconds | Histogram | Module startup time |
fivem_rpc_calls_total | Counter | RPC call count by direction |
fivem_rpc_duration_seconds | Histogram | RPC latency |
fivem_db_operations_total | Counter | Database operations |
fivem_server_uptime_seconds | Gauge | Server uptime |
fivem_player_position_x | Gauge | Player X coordinate (per-player) |
fivem_player_position_y | Gauge | Player Y coordinate (per-player) |
fivem_player_position_z | Gauge | Player 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.