Skip to content

Commit

Permalink
[pcp] collect 12 newest pmlogger files regardless of size
Browse files Browse the repository at this point in the history
- collect reasonable count of pmlogger files instead of sizelimit
 - (configurable via pcp.pmloggerfiles plugin option
- prevent pmlogger/pmmgr binary files to be truncated/tailed

Resolves: #1496

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
  • Loading branch information
pmoravec authored and bmr-cymru committed Mar 12, 2019
1 parent bcc939b commit dbb76f0
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions sos/plugins/pcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class Pcp(Plugin, RedHatPlugin, DebianPlugin):

# size-limit of PCP logger and manager data collected by default (MB)
option_list = [
("pcplogs", "size-limit in MB of pmlogger and pmmgr logs", "", 100),
("pmmgrlogs", "size-limit in MB of pmmgr logs", "", 100),
("pmloggerfiles", "number of newest pmlogger files to grab", "", 12),
]

pcp_sysconf_dir = None
Expand Down Expand Up @@ -71,8 +72,10 @@ def pcp_parse_conffile(self):
return True

def setup(self):
self.limit = (None if self.get_option("all_logs")
else self.get_option("pcplogs"))
self.sizelimit = (None if self.get_option("all_logs")
else self.get_option("pmmgrlogs"))
self.countlimit = (None if self.get_option("all_logs")
else self.get_option("pmloggerfiles"))

if not self.pcp_parse_conffile():
self._log_warn("could not parse %s" % self.pcp_conffile)
Expand Down Expand Up @@ -116,10 +119,21 @@ def setup(self):
# Make sure we only add the two dirs if hostname is set, otherwise
# we would collect everything
if self.pcp_hostname != '':
for pmdir in ('pmlogger', 'pmmgr'):
path = os.path.join(self.pcp_log_dir, pmdir,
self.pcp_hostname, '*')
self.add_copy_spec(path, sizelimit=self.limit)
# collect pmmgr logs up to 'pmmgrlogs' size limit
path = os.path.join(self.pcp_log_dir, 'pmmgr',
self.pcp_hostname, '*')
self.add_copy_spec(path, sizelimit=self.sizelimit, tailit=False)
# collect newest pmlogger logs up to 'pmloggerfiles' count
files_collected = 0
path = os.path.join(self.pcp_log_dir, 'pmlogger',
self.pcp_hostname, '*')
pmlogger_ls = self.get_cmd_output_now("ls -t1 %s" % path)
if pmlogger_ls:
for line in open(pmlogger_ls).read().splitlines():
self.add_copy_spec(line, sizelimit=None)
files_collected = files_collected + 1
if self.countlimit and files_collected == self.countlimit:
break

self.add_copy_spec([
# Collect PCP_LOG_DIR/pmcd and PCP_LOG_DIR/NOTICES
Expand Down

0 comments on commit dbb76f0

Please sign in to comment.