util.monitor.register
Client
Registers a custom stat with a user-supplied sampler function
Syntax
local status = util.monitor.register(
id,
name,
exec,
format
)Scoped to the registering environment — automatically cleaned up on environment destruction.
- Unique IDs — if
idalready exists, returnsfalse; useutil.monitor.unregisterfirst to replace it. - Sampler function —
execis called by Godot'sPerformancesingleton on demand and must return a singlenumber. - Godot integration — registered stats appear in Godot's built-in performance profiler alongside native stats.
Parameters
| Type | Name | Description |
|---|---|---|
string | id | Unique string identifier for this stat |
string | name | Human-readable display name shown in the Godot profiler |
function | exec | Sampler function invoked to read the current value Must return a single number |
util.monitor.stat_format | format | Display format for the value in the profiler |
Returns
| Type | Name | Description |
|---|---|---|
bool | status | true on successful registration, false otherwise |
Examples
util.monitor.register("my_resource:entity_count", "Entity Count", function()
return entity_manager.count()
end, util.monitor.stat_format.QUANTITY)util.monitor.register("my_resource:cache_size", "Cache Size", function()
return cache.byte_size()
end, util.monitor.stat_format.MEMORY)util.monitor.register("my_resource:cpu_load", "CPU Load", function()
return profiler.get_load()
end, util.monitor.stat_format.PERCENTAGE)local ok = util.monitor.register("my_resource:tick_rate", "Tick Rate", function()
return tick_system.get_rate()
end, util.monitor.stat_format.QUANTITY)
if not ok then
core.engine.print("warn", "Stat already registered")
end