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
To prevent pmlogger binary files to be truncated and to collect
reasonable count of the files (configurable via pcp.pmloggerfiles
plugin option).

Resolves: #1496

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
  • Loading branch information
pmoravec committed Dec 3, 2018
1 parent 848b110 commit 190415b
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),
("pmgrlogs", "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("pmgrlogs"))
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 'pmgrlogs' size limit
path = os.path.join(self.pcp_log_dir, 'pmmgr', self.pcp_hostname,
'*')
self.add_copy_spec(path, sizelimit=self.sizelimit)
# 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 190415b

Please sign in to comment.