I have multiple services and journald is used and each log entry has different fields, I would like each log entry to be displayed in loki/grafana.
Right now only “msg” field is being displayed.
How can I remove all the system fields that are prefixed by “_” and show the logs in grafana as:
For example (passing journalctl -o json-pretty):
{
"ROLE" : "manager",
"_UID" : "1001",
"MESSAGE" : "Some short message",
"DUTYSLOT" : "123",
"SLOTINEPOCH" : "10",
"_PID" : "34779",
"_GID" : "1001",
"_SELINUX_CONTEXT" : "unconfined\n",
"__REALTIME_TIMESTAMP" : "1608325979002140",
"_COMM" : "run-v1.0.",
"CURRENTSLOT" : "125163",
"__CURSOR" : "1",
"_HOSTNAME" : "server",
"_CMDLINE" : "/home/mo/run.sh --config-file=/etc/run/run.yaml",
"__MONOTONIC_TIMESTAMP" : "1",
"_SOURCE_REALTIME_TIMESTAMP" : "1",
"_MACHINE_ID" : "1",
"_SYSTEMD_CGROUP" : "/system.slice/run.service",
"_SYSTEMD_INVOCATION_ID" : "1",
"PREFIX" : "run",
"PRIORITY" : "6",
"_CAP_EFFECTIVE" : "0",
"_TRANSPORT" : "journal",
"_EXE" : "/home/mo/run/run-v1.0.5-linux-amd64",
"_BOOT_ID" : "1",
"SECONDSLEFT" : "48",
"_SYSTEMD_UNIT" : "run.service",
"_SYSTEMD_SLICE" : "system.slice"
}
It looks like this only in grafana:
Some short message
Some short message
Some short message
Some short message
Instead I want to show the fields as well, removing everything with _ and all system fields:
{
"MESSAGE" : "Some short message",
"DUTYSLOT" : "123",
"SLOTINEPOCH" : "10",
"CURRENTSLOT" : "125163",
"SECONDSLEFT" : "48",
}
And Grafana can show them in one single line:
Some short message, DUTYSLOT=123, SLOTINEPOCH=10, CURRENTSLOT=125163, SECONDSLEFT=48
Some short message, DUTYSLOT=123, SLOTINEPOCH=10, CURRENTSLOT=125163, SECONDSLEFT=60
Some short message, DUTYSLOT=123, SLOTINEPOCH=10, CURRENTSLOT=125163, SECONDSLEFT=80
How can I do something like that? Right now my grafana loki is missing a lot of fields. I have hundreds of fields I want to expose cause every service has their own fields.