All products

np_net

Network metrics for FiveM servers. np_net counts which events cost bytes, broadcasts and handler time, and why players drop. Prometheus scrapes the numbers and Grafana shows them. It only measures: no event is changed, delayed, merged or dropped.

v1.0.0StandaloneMeasures onlyGrafana dashboard included
Price TBAStore link follows at release
InstallationDocumentation
Version
1.0.0
Frameworks
None needed. Shim es_extended to see ESX callbacks
Dependencies
None. Measured resources must be Lua 5.4
Database
None
Monitoring
Prometheus + Grafana, as a docker compose stack in monitoring/
Endpoint
/np_net/metrics behind a Bearer token, optional IP list
Optional
np_admin (permissions, staff tools, live settings, audit log)
Permissions
np_admin nodes np_net.view and np_net.manage, no ACE. The console command is console only
Overview and events: players, ping, hitches, server tick p95 and net egress, then the top events by egress as a table and a graph
Overview and events: players, ping, hitches, server tick p95 and net egress, then the top events by egress as a table and a graph

np_net has no in-game UI. These are renders of its provisioned Grafana dashboard and the npnet console command with mock data, at 1920×1080. Names and numbers are made up.

What's in it

One manifest line per resource. The shim counts in local tables and hands np_net a delta every 5 seconds, so nothing is sent per event.

Per event, per resource

  • Sends, normal and latent, with their payload bytes.
  • Server egress as bytes × recipients, and broadcasts to -1.

Handler time

  • Net events received, time spent in their handlers and the slowest run.
  • Server and client side: clients send one batched report every 30 s.

Why players drop

  • Timeout, reliable overflow, exiting, crash, kicked, banned, resource, other.
  • Players, average and highest ping every 5 s.

Server tick

  • A histogram of the time between two server ticks.
  • A hitch counter, 150 ms by default.

State bags and memory

  • State bag changes per key and bag type, value bytes if you want them.
  • Lua memory of every shimmed resource, server and client.

Prometheus and Grafana

  • /np_net/metrics behind a Bearer token, optional IP list.
  • A docker compose stack with a provisioned dashboard: eight rows, 33 panels.

Console

  • npnet top by bytes, count, egress or handler time, without Grafana.
  • npnet patch np_* adds the shim line to every manifest.

Measures only

  • Same targets, same arguments, same source, same return values.
  • Errors in handlers are not caught. Nothing is merged, delayed or dropped.

A closer look

Events

The Overview and Events rows answer the first question: what costs the bandwidth. Filter by server, resource and side.

The Overview and Events rows of the np_net dashboard: stats, players and ping, event traffic, the top events by egress as a table and as a graph
  • Payload bytes once per send, and egress as bytes × recipients. A broadcast to 120 players counts 120 times.
  • Broadcast share: how many server sends go to -1. High often means an event only some players need.
  • Latent vs normal payload bytes, so you see what already goes through the latent queue.
  • Client → server: the events clients flood the server with, from their batched reports.

Handlers and the server tick

When the tick p95 goes up, the handler graphs show what ran at the same time.

The Handlers and Server tick rows: top handlers by time spent and by max single run, the tick heatmap, the tick quantiles against the hitch line and hitches per minute
PanelWhat it shows
Time spentSeconds per second in the handlers of each net event, server and client side
Max single runThe slowest run in the last window. Handler time is wall time, so a handler that calls Wait() includes the wait
Handler costTime and receives side by side, for the average cost of one arrival
TickThe time between two server ticks as a heatmap and p50 / p95 / p99. Buckets from 10 ms to 1 s
HitchesTicks slower than np_net_hitch_ms (150), per minute

Player drops and state bags

Every drop reason is sorted into one of eight categories. State bags are counted by bag type and key, never by bag id, so a thousand entities stay one series per key.

The Player drops and State bags rows: drops by category over time, drops in range, changes per bag type and the busiest keys
  • reliable_overflow usually means a resource sends too much, too fast. Look at the egress graph right before it.
  • Categories: banned, reliable_overflow, crash, timeout, kicked, then the drop code of newer artifacts, resource, exiting, other.
  • State bags: global, player, entity and other, per key. Value bytes with np_net_statebag_bytes 1.
  • Lua memory per shimmed resource. Client side: the average of every connected client's latest report.

Console and np_admin

No Grafana at hand? npnet top prints the most expensive events in the server console.

npnet status and npnet top in the server console, the Prometheus target and a patched fxmanifest.lua
CommandWhat
npnet statusShimmed resources, last push, Lua memory, series, endpoint state
npnet topBy bytes, count, egress or handler, any number of rows
npnet resetZero every counter
npnet patchAdd the shim line to one resource, np_* or all; unpatch removes exactly those lines
np_adminNodes np_net.view / np_net.manage, staff tools for top events, status and reset (output in F8), live settings and the audit log

How the shim works

init.lua runs inside each resource's own Lua state, on both sides, and wraps the event functions there.

  • A send packs its arguments once and calls the same *Internal native the CitizenFX scheduler calls, so the size is known without packing twice.
  • Handlers get the same arguments (nil holes included), source and return values. RemoveEventHandler keeps working.
  • Counts stay in local tables and go to np_net as one delta every 5 s. Without np_net running, the shim keeps counting and drops the deltas.
  • If a native or msgpack.pack_args is missing, the original function is called and the send is counted without bytes.
SideWrapped
serverTriggerClientEvent, TriggerLatentClientEvent
clientTriggerServerEvent, TriggerLatentServerEvent
bothRegisterNetEvent, RegisterServerEvent, AddEventHandler

Security

Port 30120 is public for players, so the endpoint is closed until you set a token.

ConcernHow it's handled
EndpointAnswers 503 until np_net_token is set. Prometheus sends Authorization: Bearer; the compare doesn't stop at the first wrong character
IP listnp_net_allow_ips for a fixed scrape address. Firewall /np_net/metrics to the Prometheus host as well
TokenA server convar with set, never setr. Never in a file and never sent to clients
Client reportsUntrusted. Types, sizes and ranges checked, one report per player per interval, only resources that exist, rejected reports counted by reason
GrafanaBound to 127.0.0.1. Reach it through an SSH tunnel or a VPN
  • Client numbers find problems, they don't prove anything. A modified client can report any number. Server numbers are measured on the server.
  • Run the stack on a small separate box. Prometheus and Grafana on the FXServer machine cause exactly the hitches the dashboard is meant to find.
  • The scrape is plain HTTP: run it over a private network or WireGuard / Tailscale when the boxes aren't in one data centre.

Set it up

Compatibility

Any Lua 5.4 resource can be shimmed, np_* or not. np_net uses no framework; to see framework traffic, shim the framework itself.

SetupWhat to shim
es_extendedESX callbacks run in es_extended's Lua state. npnet patch es_extended to see esx:triggerServerCallback and friends
qbx_core / qb-coreA function you get from the core's export runs in the core's state. Patch the core to see its events
ox_libCallbacks run in the resource that uses them. Its shim counts them, as long as the shim line comes before @ox_lib/init.lua
StandalonePatch the resources you want to see. Drops, tick, ping and state bags need no shim
Not coveredWhy
JS and C# resourcesThe shim is Lua
Unshimmed resourcesInvisible to the event metrics
Engine trafficEntity sync, voice and state bag replication aren't events. The tick and FXServer's own /perf/ show their effect
Local eventsTriggerEvent never touches the network and isn't counted

Installation

On start the console shows ready, metrics at /np_net/metrics (open, bearer token set).

  1. Copy np_net into your resources and add it to server.cfg, early:
    set np_net_token "a-long-random-string"   # set, never setr
    ensure np_net                             # before the resources you measure
  2. Add the shim to each resource you want to see, as the first script line of its fxmanifest.lua, before any file that copies the event functions into locals and before @ox_lib/init.lua:
    shared_script '@np_net/init.lua'
  3. Or let np_net do it from the server console, then restart each patched resource:
    npnet patch np_*        # every resource starting with np_
    npnet patch es_extended
    npnet unpatch all       # removes exactly the lines np_net added
  4. Point Prometheus at http://<server>:30120/np_net/metrics with Authorization: Bearer <token>, or use the stack in monitoring/ (next tab).

Prometheus and Grafana

monitoring/ is a docker compose stack: Prometheus v3 and Grafana with the np_net dashboard as the home dashboard.

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

# same value as np_net_token in server.cfg
printf '%s' 'paste-the-token-here' > secrets/np_net_token

docker compose up -d

# from your PC: both only listen on 127.0.0.1
ssh -L 3000:127.0.0.1:3000 -L 9090:127.0.0.1:9090 you@monitoring-box
Dashboard rowPanels
OverviewPlayers, ping, hitches, tick p95, net egress, event traffic
EventsTop events by egress, sends/s, client → server bytes, broadcast share, latent vs normal
HandlersTime spent, max single run, handler cost
Player dropsDrops by category, drops in range
Server tickHeatmap, quantiles, hitches per minute
State bagsChanges per bag type, top keys
Resources & exporterLua memory, shimmed resources, series, version
Client reportsReports per second, rejected by reason

Several servers: one target file with a server label each, picked in the dashboard's Server variable. FXServer's own /perf/ endpoint can be added as an optional job; its path and auth differ between artifacts, so check it with curl -i first.

Configuration

Everything is a convar in server.cfg. With np_admin, most of them can be changed live, and an np_admin value beats the convar.

ConvarDefaultWhat
np_net_tokenemptyBearer token; empty = 503
np_net_allow_ipsemptyComma list of IPs allowed to scrape
np_net_flush_ms5000How often each shim hands over its delta (setr)
np_net_client_report_ms30000Client report interval, 0 = off (setr)
ConvarDefaultWhat
np_net_max_series2000Label series kept; beyond it __other__
np_net_tick1Measure the server tick
np_net_hitch_ms150A slower tick is a hitch
np_net_statebags1Count state bag changes
np_net_statebag_bytes0Also count value bytes (costs CPU)

The token, the IP list and the flush interval stay convars. Everything else is in np_admin's Resource settings → np_net.

Questions

Does it change how my events behave?

No. Every event goes to the same targets through the same natives, handlers get the same arguments, source and return values, and errors are not caught. np_net never merges, delays or drops anything.

Does it cost performance?

Very little. A send is packed once, as it would be anyway. Counts stay in local tables and go to np_net as one delta every 5 seconds; clients send one latent report every 30 seconds. The scrape renders numbers np_net has already aggregated.

Do I need Grafana?

No. npnet top prints the most expensive events in the console, and any Prometheus-compatible tool can scrape the endpoint. The docker compose stack in monitoring/ is the quickest way to the dashboard.

Why don't I see ESX callbacks?

They run in es_extended's Lua state, not in the resource that asked. Patch es_extended too and they appear under resource="es_extended".

Can I trust the client numbers?

Use them to find problems, not as proof against a player. A modified client can report any number. np_net checks every report, rate-limits each player and counts rejected reports, but only server-side numbers are measured by the server itself.

Does it use ACE permissions?

No. The console command is console only. With np_admin, staff get the nodes np_net.view and np_net.manage for the staff tools.

Works well with

See what your events cost.

Every metric, the dashboard and the monitoring stack are in the docs.

Read the docs