From 6145fe2c40ae284fcd72f7e7e70dfa51e0a8266d Mon Sep 17 00:00:00 2001 From: Peter Portante Date: Sat, 19 Apr 2014 14:03:46 +0100 Subject: Handle compressed sar binary data files better We now collect all compressed and uncompressed sar?? and sa?? data files. Given that tailing the text output is not very useful, we add an option to not perform the tail when we have reached the limit. NOTES: * The 20 MB limit applies to each *set* of files being collected, so there there is a 20 MB limit for the total number of sa??* files and _separate_ 20 MB limit for sar??* files collected * The 20 MB limit *does not apply* to the generated command output, so if there is a 200+ MB sa?? data file present, that file won't be collected, but the resulting 200+ MB sar?? and sar??.xml files will still be collected in full * The generated command output for missing sar files is only generated from uncompressed binary data files * The generated command output for the XML files is also only generated from uncompressed binary data files Signed-off-by: Peter Portante Signed-off-by: Bryn M. Reeves --- sos/plugins/sar.py | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/sos/plugins/sar.py b/sos/plugins/sar.py index bd794fc8..8b641baa 100644 --- a/sos/plugins/sar.py +++ b/sos/plugins/sar.py @@ -32,26 +32,40 @@ class Sar(Plugin,): if self.get_option("all_sar"): self.sa_size = 0 - self.add_copy_spec_limit(os.path.join(self.sa_path, "sar[0-9]*"), - sizelimit = self.sa_size) - self.add_copy_spec_limit(os.path.join(self.sa_path, "sa[0-9]*"), - sizelimit = self.sa_size) + # Copy all sa??, sar??, sa??.* and sar??.* files, which will net + # compressed and uncompressed versions, typically. + for suffix in ('', '.*'): + self.add_copy_spec_limit( + os.path.join(self.sa_path, "sa[0-3][0-9]" + suffix), + sizelimit = self.sa_size, tailit=False) + self.add_copy_spec_limit( + os.path.join(self.sa_path, "sar[0-3][0-9]" + suffix), + sizelimit = self.sa_size, tailit=False) try: dirList = os.listdir(self.sa_path) except: self.log_warn("sar: could not list %s" % self.sa_path) return - # find all the sa file that don't have an existing sar file + # find all the sa files that don't have an existing sar file for fname in dirList: - if fname[0:2] == 'sa' and fname[2] != 'r': - sar_filename = 'sar' + fname[2:4] - sa_data_path = os.path.join(self.sa_path, fname) - if sar_filename not in dirList: - sar_cmd = 'sh -c "LANG=C sar -A -f %s"' % sa_data_path - self.add_cmd_output(sar_cmd, sar_filename) - sadf_cmd = "sadf -x %s" % sa_data_path - self.add_cmd_output(sadf_cmd, "%s.xml" % fname) - self.add_copy_spec(os.path.join(self.sa_path, "sar*")) + if fname.startswith('sar'): + continue + if not fname.startswith('sa'): + continue + if len(fname) != 4: + # We either have an "sa" or "sa?" file, or more likely, a + # compressed data file like, "sa??.xz". + # + # FIXME: We don't have a detector for the kind of compression + # use for this file right now, so skip these kinds of files. + continue + sa_data_path = os.path.join(self.sa_path, fname) + sar_filename = 'sar' + fname[2:] + if sar_filename not in dirList: + sar_cmd = 'sh -c "LANG=C sar -A -f %s"' % sa_data_path + self.add_cmd_output(sar_cmd, sar_filename) + sadf_cmd = "sadf -x %s" % sa_data_path + self.add_cmd_output(sadf_cmd, "%s.xml" % fname) class RedHatSar(Sar, RedHatPlugin): -- cgit