Skip to content

Commit

Permalink
[plugins] Speedup journal collection
Browse files Browse the repository at this point in the history
Instead of generating all the logs and tailing the last 100M,
we get the first 100M of 'journalctl --reverse' that we then
reverse again using tac_logs().

On journalctl timeout we now get the most recents logs
where previously we were getting some random old logs.

During collection, logs are now buffered on disk, so we use 2xsizelimit.
Previously buffering was in RAM (also 2xsizelimit).

On my test server, logs plugin runtime goes from 34s to 9.5s.

Signed-off-by: Etienne Champetier <[email protected]>
  • Loading branch information
champtar committed Jan 26, 2025
1 parent 39b3fde commit 2ff50e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3088,8 +3088,15 @@ def add_journal(self, units=None, boot=None, since=None, until=None,
if output:
journal_cmd += output_opt % output

fname = journal_cmd
tac = False
if log_size > 0:
journal_cmd = f"{journal_cmd} --reverse"
tac = True

self._log_debug(f"collecting journal: {journal_cmd}")
self._add_cmd_output(cmd=journal_cmd, timeout=timeout,
tac=tac, to_file=True, suggest_filename=fname,
sizelimit=log_size, pred=pred, tags=tags,
priority=priority)

Expand Down
2 changes: 1 addition & 1 deletion tests/report_tests/plugin_tests/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_journal_collected(self):
_m = self.get_plugin_manifest('cups')
ent = None
for cmd in _m['commands']:
if cmd['exec'] == 'journalctl --no-pager --unit cups':
if cmd['exec'] == 'journalctl --no-pager --unit cups --reverse':
ent = cmd
assert ent, "No manifest entry for journalctl cups"

Expand Down

0 comments on commit 2ff50e2

Please sign in to comment.