Using Lua Scripts in Elastic Beats for Lightweight Edge Processing
Learn how to add Lua processors to Filebeat for custom transformations while monitoring resource impact.
07 Apr 2026, 14:40 UTC

script processor with Lua.
Example: Mask an API Key
Assume a log line contains an api_key field that must be masked before leaving the host.
# filebeat.yml snippet
processors:
- script:
lang: lua
source: |
function process(event)
if event.fields.api_key then
local key = event.fields.api_key
-- keep last 4 chars, mask the rest
event.fields.api_key = string.rep('*', #key - 4) .. string.sub(key, -4)
end
return event
end
Where to apply: Edit filebeat.yml on the source host and restart the Filebeat service.
Permissions: The user running Filebeat must be able to read the configuration file.
Expected check: After restart, view events in Kibana; the api_key field should show asterisks followed by the last four characters.
Risk: A poorly written Lua script (e.g., infinite loop or heavy regex) can spike CPU on the host and trigger backpressure, slowing log ingestion.
Trade‑off: Edge vs. Central Processing
Moving logic to the edge has advantages and drawbacks.
| Aspect | Edge Processing (Lua) | Central Processing (Logstash) |
|---|---|---|
| CPU impact | Consumes resources on the application server | Uses a dedicated processing cluster |
| Security | Sensitive data is masked before it leaves the host | Raw data travels over the network |
| Updates | Requires restarting the Beat on each host | Can be changed centrally without touching agents |
beat.cpu.usage and beat.mem.usage (available via Metricbeat or the Beat’s HTTP endpoint). A rise in CPU accompanied by a drop in the events.out rate signals that the Lua script is too heavy. At that point, either simplify the script or offload the work to Logstash.