Skip to content

Grafana & Prometheus ​

monitoring/ in the resource is a docker compose stack: Prometheus v3 and Grafana, with a provisioned dashboard np_net overview (uid np-net-overview). It runs on any box with Docker and Compose v2, ideally not the FXServer machine (see Where to run it).

monitoring/
├── docker-compose.yml               prometheus v3 + grafana, restart unless-stopped
├── .env.example                     copy to .env
├── secrets/np_net_token             you create this (gitignored)
├── prometheus/prometheus.yml        scrape jobs np_net, fxserver_perf (optional), prometheus
├── prometheus/targets/*.example.yml file_sd target lists (copy to *.yml)
├── grafana/provisioning/            datasource (uid np-net-prom) + dashboard provider
├── grafana/dashboards/np_net.json   the dashboard
└── data/                            Prometheus TSDB + Grafana DB (gitignored)

Quick start ​

On the monitoring box:

sh
cd monitoring
cp .env.example .env
$EDITOR .env                      # GF_ADMIN_PASSWORD, FIVEM_TARGET=host:30120

# token: same value as `set np_net_token "..."` in server.cfg
printf '%s' 'paste-the-token-here' > secrets/np_net_token
sudo chown 65534:65534 secrets/np_net_token && chmod 400 secrets/np_net_token

# data dirs must be writable by the container users
mkdir -p data/prometheus data/grafana
sudo chown -R 65534:65534 data/prometheus   # prometheus runs as nobody
sudo chown -R 472:0 data/grafana            # grafana runs as uid 472

docker compose up -d
  1. Check the target is UP: curl -s 127.0.0.1:9090/api/v1/targets | grep health, or open http://127.0.0.1:9090/targets. 401 = wrong token, 404 = np_net not started or wrong port.
  2. Open Grafana at http://127.0.0.1:3000 (user admin, password from .env). The np_net dashboard is the home dashboard and lives in the np_net folder.

Grafana and Prometheus only listen on 127.0.0.1. From your PC:

sh
ssh -L 3000:127.0.0.1:3000 -L 9090:127.0.0.1:9090 you@monitoring-box

Targets ​

Prometheus can't read env vars in its config, so there are two ways to set the server:

  • One server: set FIVEM_TARGET=host:port in .env. On startup the container writes it into a file_sd file with the label server=$FIVEM_SERVER_NAME. Run docker compose up -d again after changing it.
  • Several servers or custom labels: leave FIVEM_TARGET empty, cp prometheus/targets/np_net.example.yml prometheus/targets/np_net.yml and edit it. Prometheus picks up changes within a minute, no restart needed. Give each server a unique server label; the dashboard has a Server picker.

Don't do both for the same server, or it is scraped twice. If FXServer runs on the same machine as Docker, use host.docker.internal:30120.

Settings ​

What Where
Scrape interval (15 s) prometheus/prometheus.yml → global.scrape_interval
Retention (30 d) PROM_RETENTION in .env
Grafana port / exposure ports: of grafana in docker-compose.yml
Reload the Prometheus config curl -X POST http://127.0.0.1:9090/-/reload

Token rotation: overwrite secrets/np_net_token. Prometheus reads it on every scrape, so nothing restarts. Change np_net_token in server.cfg and restart np_net at the same time.

The provisioned dashboard can be edited in the UI, but the file on disk wins on the next change. Use Save as with a new uid for your own variants.

The dashboard ​

Variables at the top: Server, Resource and Side (server / client). Rows:

Row Panels
Overview Players, Avg ping, Max ping, Hitches (last 1h), Server tick p95, Net egress · Players & ping · Event traffic (server egress vs. client → server payload)
Events Top events by egress (table) · Top 10 events by egress bytes/s · Top 10 events by sends/s · Top 10 client → server events by payload bytes/s · Broadcast share and Broadcast share over time · Latent vs normal (payload bytes/s)
Handlers Top 10 handlers by time spent (s/s) · Top 10 handlers by max single run · Handler cost (table, with receives)
Player drops Drops by category · Drops in range (table)
Server tick Tick time distribution (heatmap) · Tick time quantiles · Hitches per minute
State bags State bag changes/s by bag · Top 10 state bag keys by changes/s · Top state bag keys (table, with bytes)
Resources & exporter Lua memory by resource (top 15) · Shimmed resources · Exported series · Dropped series (range) · np_net version
Client reports Client reports/s (accepted vs. rejected) · Rejected reports by reason
Heatmaps Heatmap points/min by layer · Heatmap points ignored (range). The maps are in the heatmap viewer

How to read it:

  • Net egress high, one event on top of "Top events by egress": that event is your bandwidth. A high broadcast share usually means a TriggerClientEvent(name, -1, …) that only some players need.
  • reliable_overflow drops: look at the sends/s and egress of the minutes before. A resource sending a large table to a player in a loop fills the reliable buffer.
  • Tick p95 up and hitches: check "Top 10 handlers by max single run" for the same time. Remember handler time includes Wait().
  • Dropped series above 0: some resource builds event names from data. See Metrics → Series cap.

FXServer /perf/ (optional) ​

FXServer has a built-in Prometheus endpoint at http://<server>:30120/perf/ (txAdmin reads it). It is a separate scrape job, fxserver_perf, and off by default. Its path, access rules and metric names have changed between artifacts, so check it on yours first:

sh
curl -i http://<server>:30120/perf/

Turn it on with FIVEM_SCRAPE_PERF=true in .env or by copying prometheus/targets/fxserver_perf.example.yml. The np_net dashboard doesn't use it; query it in Explore.

Security ​

  • Firewall /np_net/metrics. Port 30120 is public for players, so the token is the only thing protecting the endpoint unless you filter it. Put a reverse proxy or the host firewall in front of the HTTP side so only the Prometheus host can reach /np_net/metrics (and /perf/), or at least keep a long random token (openssl rand -hex 32). np_net_allow_ips adds an IP check inside np_net.
  • The scrape is plain HTTP. Run it over a private network or a VPN (WireGuard, Tailscale) when the boxes aren't in the same data centre.
  • Don't make Grafana public. It binds to 127.0.0.1:3000. Use an SSH tunnel or VPN. If you must expose it, put it behind a TLS reverse proxy, set GF_SERVER_ROOT_URL and keep sign-up and anonymous access off (the default here).
  • Prometheus has no auth at all. Keep 9090 on localhost.

The token compare doesn't stop at the first wrong character, so timing doesn't leak it.

Where to run it ​

Run Prometheus and Grafana on a separate small box: a 1–2 vCPU / 2 GB VPS is plenty for one FXServer at 15 s. Prometheus compactions and Grafana queries are CPU bursts, and on the same machine they compete with FXServer's main thread, which shows up as exactly the hitches this dashboard is meant to find. If it has to be the same host, pin the containers away from FXServer's cores (cpuset: "3" per service in compose) and give FXServer the higher priority.

The scrape itself is cheap for FXServer: one HTTP request every 15 s that renders the text np_net has already aggregated.

Without Docker ​

Install the official prometheus binary and the Grafana package, copy prometheus/prometheus.yml, a target file and the token into /etc/prometheus/, and the provisioning files and np_net.json into Grafana's provisioning folders. Bind both to 127.0.0.1. The full systemd unit and the exact commands are in monitoring/README.md in the resource.

The /prometheus/generated_targets/*.json entries in prometheus.yml only exist in Docker. Without them Prometheus logs a harmless warning, or delete those two lines.