Ingesting logs from `journalctl` as json, and parsing timestamps
See original GitHub issueI was pointed at seqcli
which apparently could be used in a tailing fashion with journalctl to read journald logs. I tried it out, and instead of reading and parsing text, I went the route with json parsing (to get all the structured logs goodies).
I came up with this:
journalctl -f -o json | \
jq -c '. + {
"@m":.MESSAGE,
"host":._HOSTNAME,
"@l":(.PRIORITY|tonumber),
"@t":(.__REALTIME_TIMESTAMP|tonumber)} |
del(.MESSAGE, ._HOSTNAME,.PRIORITY,.__REALTIME_TIMESTAMP)
' | seqcli ingest --json
There are a few points here:
- The timestamp is rejected by
seqcli ingest
, withThe value of
@ton line 1 is not in a supported format.
- I could format the timestamp (unix milliseconds) as some datetime, but I think that’s a waste…
- Should I lowercase all properties?
- I couldn’t pass in json unless it was newline delimited, I kinda expected that to work though - compact is better anyways, but maybe some source doesn’t come in compact in the future …
- I’ll submit this as an alternate to your command in the docs when it’s pretty 😃
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to View and Manage Systemd Logs with Journalctl
Head over to Logtail and start ingesting your logs in 5 minutes. ... be useful to change the format to an easy to...
Read more >Using journalctl - The Ultimate Guide To Logging - Loggly
Journalctl is a utility for querying and displaying logs from journald, ... to parse. json-pretty will show each log entry in easy-to-read json...
Read more >How To Use Journalctl to View and Manipulate Systemd ...
To see the logs that the journald daemon has collected, use the journalctl command. When used alone, every journal entry that is in...
Read more >And that's why journald is such a cool thing. \* Want to ...
It's in there. * Want to know where to continue parsing? It supports cursors. * Want to save disk space? It uncompresses logs...
Read more >Injecting structured json logs into journald - systemd
I get the impression that there might be a way to write to the systemd journal, json data directly without first converting it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually, I imagined that seqcli would accept and interpret values like the following:
1262304000 < N < 1262304000000
, assume seconds (2010-01-01
)1262304000000 < N < 1262304000000
, assume milliseconds (2010-01-01
)1262304000000000 < N < 1262304000000000
, assume microseconds (2010-01-01
)I chose the cutoff to be 2010, but any number will do - there will be some overlap though for very early timestamps, where you cannot distinguish between the different precisions of unix timestamps.
Can’t find the docs in github - so how can I improve them? 😃
I’ve ended on this:
This:
Future readers should be aware that: