Short timestamp format in mysql slow query logs
Issue: mysql (mariadb) create slow log with timestamp value in SECONDS:
For collect actual data to the any log collector we should to set actual timestamp of event from source information.
For Openobserve it's microseconds.
I didn't found any options in mysql or mariadb to set the such format of timestamp in slow query logs . :(
Using solution for fluent-bit: https://github.com/derifgig/fluent-bit-sql-slow-query-log
Add additional filter with lua:
fluentbit_pipelines_sqlslow:
- file: local
content:
pipeline:
inputs:
- name: tail
# ... skipped
processors:
logs:
# ... skipped
- name: lua
call: set_timestamp_microseconds
code: |
function set_timestamp_microseconds(tag, timestamp, record)
if record['timestamp'] ~= nil then
new_record = record
new_record["_timestamp"] = record['timestamp']*1000000
return 1,timestamp,new_record
else
return 0,timestamp,record
end
end
As result value in SECONDS in json.
{
"_timestamp":1735641280000000,
"bytes_sent":"65",
"hostname":"srv",
"lock_time":"0.000000",
"qc_hit":"No",
"query":"select sleep(3);",
"query_time":"3.000446",
"rows_affected":"0",
"rows_examined":"0",
"rows_sent":"1",
"thread_id":"25203",
"time":"241231 12:34:40",
"timestamp":"1735641280",
"user_host":"root[root] @ localhost []"
}
It's not the BEST solution, but better than timestamp of event insert on log collector's side.