Skip to content

Commit

Permalink
Use journald for kernlogs if kern.log not found
Browse files Browse the repository at this point in the history
On some hosts or sosreports kern.log may be missing so we
fall back to journald for calltrace checking if this is the
case.
  • Loading branch information
dosaboy committed Jan 11, 2025
1 parent 6a0df95 commit 3afee58
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
11 changes: 10 additions & 1 deletion hotsos/core/host_helpers/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def __init__(self, *args, **kwargs):

def format_journalctl_cmd(self, **kwargs):
""" Add optional extras to journalctl command. """
if kwargs.get("opts"):
self.cmd = f"{self.cmd} {kwargs.get('opts')}"

if kwargs.get("unit"):
self.cmd = f"{self.cmd} --unit {kwargs.get('unit')}"

Expand All @@ -84,7 +87,13 @@ def __init__(self, *args, **kwargs):
self.register_hook("pre-exec", self.preformat_sos_journalctl)

def preformat_sos_journalctl(self, **kwargs):
self.path = f"journalctl -oshort-iso -D {self.path}"
default_opts = '-oshort-iso'
if kwargs.get("opts"):
self.path = (f"journalctl {default_opts} {kwargs.get('opts')} "
f"-D {self.path}")
else:
self.path = f"journalctl {default_opts} -D {self.path}"

if kwargs.get("unit"):
self.path = f"{self.path} --unit {kwargs.get('unit')}"

Expand Down
18 changes: 15 additions & 3 deletions hotsos/core/plugins/kernel/kernlog/calltrace.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import abc
import os
import re

from hotsos.core.config import HotSOSConfig
from hotsos.core.log import log
from hotsos.core.search import (
SearchDef,
SequenceSearchDef,
)
from hotsos.core.host_helpers.cli import CLIHelperFile
from hotsos.core.plugins.kernel.kernlog.common import (
CallTraceHeuristicBase,
CallTraceStateBase,
Expand Down Expand Up @@ -483,10 +486,19 @@ def __init__(self, *args, **kwargs):
self.run()

def run(self):
for tracetype in self.tracetypes:
self.searcher.add(tracetype.searchdef, self.path)
path = self.path
with CLIHelperFile() as cli:
if not os.path.exists(path):
path = cli.journalctl(opts='-k')
else:
if HotSOSConfig.use_all_logs:
path = f"{path}*"

for tracetype in self.tracetypes:
self.searcher.add(tracetype.searchdef, path)

self.results = self.searcher.run()

self.results = self.searcher.run()
for tracetype in self.tracetypes:
if isinstance(tracetype.searchdef, SequenceSearchDef):
results = self.results.find_sequence_sections(
Expand Down
11 changes: 7 additions & 4 deletions hotsos/core/plugins/kernel/kernlog/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ def __init__(self):

@property
def path(self):
path = os.path.join(HotSOSConfig.data_root, 'var/log/kern.log')
if HotSOSConfig.use_all_logs:
return f"{path}*"
"""
Return path we want to search. By default we search kern.log but that
may not exist e.g. sosreport does not collect it if systemd-journald is
running. In that case we need to fallback to using the journal.
return path
@return: path
"""
return os.path.join(HotSOSConfig.data_root, 'var/log/kern.log')
18 changes: 15 additions & 3 deletions hotsos/core/plugins/kernel/kernlog/events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import os

from hotsos.core.config import HotSOSConfig
from hotsos.core.log import log
from hotsos.core.host_helpers.cli import CLIHelperFile
from hotsos.core.plugins.kernel.kernlog.common import KernLogBase
from hotsos.core.search import SearchDef

Expand All @@ -7,10 +11,18 @@ class KernLogEvents(KernLogBase):
""" Kern log events info. """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for event in [self.over_mtu_dropped_packets_search_def]:
self.searcher.add(event, self.path)
path = self.path
with CLIHelperFile() as cli:
if not os.path.exists(path):
path = cli.journalctl(opts='-k')
else:
if HotSOSConfig.use_all_logs:
path = f"{path}*"

for event in [self.over_mtu_dropped_packets_search_def]:
self.searcher.add(event, path)

self.results = self.searcher.run()
self.results = self.searcher.run()

@property
def over_mtu_dropped_packets_search_def(self):
Expand Down

0 comments on commit 3afee58

Please sign in to comment.