lua는 Lua스크립트를 실행해 다양한 작업을 처리한다.
다음은 타임스탬프를 추가하는 예제이다.
[SERVICE]
Flush 1
Daemon off
[INPUT]
Name tail
Tag my_tail
path /var/log/logf/app.log
[FILTER]
Name lua
Match my_tail
script script.lua
call append_timestamp
[OUTPUT]
Name stdout
Match my_tail
function append_timestamp(tag, timestamp, record)
new_record = record
new_record["timestamp"] = timestamp
return 1, timestamp, new_record
end
function format_timestamp(tag, timestamp, record)
new_record = record
print(new_record["timestamp"])
new_record["timestamp"] = new_record["timestamp"]:gsub(",", ".")
return 1, timestamp, new_record
end
function stringtonumber(tag, timestamp, record)
new_record = record
new_record["response_time"] = tonumber(new_record["response_time"])
return 1, timestamp, new_record
end
function stringtonumber(tag, timestamp, record)
new_record = record
new_record["time"] = new_record["time"]:gsub("Jan", "01"):gsub("Feb", "02"):gsub("Mar", "03"):gsub("Apr", "04"):gsub("May", "05"):gsub("Jun", "06"):gsub("Jul", "07"):gsub("Aug", "08"):gsub("Sep", "09"):gsub("Oct", "10"):gsub("Nov", "11"):gsub("Dev", "12")
temp = {}
for word in new_record["time"]:gmatch("%S+") do
table.insert(temp, word)
end
new_record["time"] = string.format("%s-%s-%s %s.000", temp[4], temp[3], temp[2], temp[5])
end