context-variables.stats
- stats Context Variables
- Process Statistics
- stats.process_rss_bytes
- stats.process_cpu_millis
- System Memory
- stats.system_mem_total_bytes
- stats.system_mem_available_bytes
- stats.system_swap_total_bytes
- stats.system_swap_used_bytes
- stats.swap_pages_in
- stats.swap_pages_out
- System CPU
- stats.system_cpu_count
- stats.system_cpu_active_millis
- stats.system_cpu_total_millis
- Load Averages
- stats.load_1m_x100
- stats.load_5m_x100
- stats.load_15m_x100
- Network Queues
- stats.udp_receive_drops
- stats.tcp_listen_overflows
- stats.tcp_listen_drops
- Example Usage
- Logging Memory Usage
stats Context Variables
The stats namespace provides read-only access to process and system statistics
including memory usage, CPU time, and load averages. These can be used in
configuration expressions, logging, and attribute assignments.
Process Statistics
stats.process_rss_bytes
Process resident set size (memory) in bytes.
Type: Integer (unsigned)
Example:
logging {
aaa {
logger "METRICS" {
console;
}
}
}
aaa {
@pipeline "LOG_MEMORY" {
log "METRICS" {
format "rss_bytes=%{stats.process_rss_bytes}";
}
}
}
stats.process_cpu_millis
Total CPU time used by the process in milliseconds (user + system).
Type: Integer (unsigned)
System Memory
stats.system_mem_total_bytes
Total system memory in bytes.
Type: Integer (unsigned)
stats.system_mem_available_bytes
Memory in bytes that the system can give to new allocations without swapping.
This includes page cache and other memory that the kernel can reclaim. The
value is MemAvailable from /proc/meminfo.
Kernels that do not report MemAvailable report unused memory instead.
Type: Integer (unsigned)
stats.system_swap_total_bytes
Total swap space in bytes.
Type: Integer (unsigned)
stats.system_swap_used_bytes
Used swap space in bytes.
Type: Integer (unsigned)
stats.swap_pages_in
Cumulative count of pages swapped in from disk.
Type: Integer (unsigned)
stats.swap_pages_out
Cumulative count of pages swapped out to disk.
Type: Integer (unsigned)
System CPU
stats.system_cpu_count
Number of CPUs available.
Type: Integer (unsigned)
stats.system_cpu_active_millis
System-wide active (non-idle) CPU time in milliseconds.
Type: Integer (unsigned)
stats.system_cpu_total_millis
System-wide total CPU time in milliseconds.
Type: Integer (unsigned)
Calculating CPU utilization: To calculate CPU utilization percentage,
compare stats.system_cpu_active_millis to stats.system_cpu_total_millis:
CPU % = (stats.system_cpu_active_millis / stats.system_cpu_total_millis) * 100
For interval-based measurements, take two snapshots and compute the delta:
CPU % = ((active2 - active1) / (total2 - total1)) * 100
Load Averages
Load averages are multiplied by 100 to preserve precision as integers. Divide by 100 to get the actual load average value.
stats.load_1m_x100
1-minute load average multiplied by 100.
Type: Integer (unsigned)
stats.load_5m_x100
5-minute load average multiplied by 100.
Type: Integer (unsigned)
stats.load_15m_x100
15-minute load average multiplied by 100.
Type: Integer (unsigned)
Network Queues
These values help detect overload.
stats.udp_receive_drops
Datagrams that the kernel dropped because the receive buffers of Radiator's open UDP sockets were full. Each socket counts from the time it was opened, so the value can decrease when a socket is closed.
Type: Integer (unsigned)
stats.tcp_listen_overflows
Number of times a TCP listen queue on the host overflowed since the host started. The value covers all applications on the host. Only available on Linux.
Type: Integer (unsigned)
stats.tcp_listen_drops
Connection attempts dropped by TCP listeners on the host since the host started, including listen queue overflows. The value covers all applications on the host.
Type: Integer (unsigned)
Example Usage
Logging Memory Usage
scripts {
lua "LOG_STATS" {
content """
local context, previous = ...
local rss = context.stats.process_rss_bytes
if rss then
print(string.format("Memory: %.2f MB", rss / 1024 / 1024))
end
return previous
""";
}
}
aaa {
policy "RADIUS" {
conditions all {
aaa.protocol == protocol.RADIUS;
}
handler "AUTH" {
@authentication {
script "LOG_STATS";
}
}
}
}