From 129f22df22c334ccabf0fcefa55aa6843d1942f2 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Fri, 19 Apr 2013 16:53:31 +0100 Subject: Fix sar plug-in sa_path usage and enable on Debian/Ubuntu Make sure that all places in the sar plug-in that need to reference the sar log path do so using the sa_path variable. This enables the plug-in to work on other distributions by changing the value of sa_path in a new subclass. Signed-off-by: Bryn M. Reeves --- sos/plugins/sar.py | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/sos/plugins/sar.py b/sos/plugins/sar.py index d07416dd..2d977ae9 100644 --- a/sos/plugins/sar.py +++ b/sos/plugins/sar.py @@ -15,38 +15,27 @@ from sos.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin import os -class sar(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): - """Generate the sar file from /var/log/sa/saXX files +class Sar(Plugin, RedHatPlugin): + """ Collect system activity reporter data """ - sapath='/var/log/sa' - sarcmd='sar' - files = (sapath, sarcmd) - - def check_enabled(self): - # check to see if we are force-enabled with no sar installation - if not os.path.exists(self.sapath) or not os.path.isdir(self.sapath): - self.soslog.error( - "sar directory %s does not exist or is not a directory" - % self.sapath) - return False - return True + packages = ('sysstat',) + sa_path = '/var/log/sa' def setup(self): - # catch exceptions here to avoid races - try: - dir_list=os.listdir(self.sapath) - except Exception, e: - self.soslog.error("sar path %s cannot be read: %s" - % (self.sapath, e)) - return - + dirList = os.listdir(self.sa_path) # find all the sa file that don't have an existing sar file - for fname in dir_list: + for fname in dirList: if fname[0:2] == 'sa' and fname[2] != 'r': sar_filename = 'sar' + fname[2:4] - if sar_filename not in dir_list: - sar_command = "sh -c \"LANG=C sar " \ - + "-A -f /var/log/sa/" + fname + "\"" - self.add_cmd_output(sar_command, sar_filename) - self.add_copy_spec("/var/log/sa/sar*") + if sar_filename not in dirList: + sar_path = os.path.join(self.sa_path, fname) + sar_command = 'sh -c "LANG=C sar -A -f %s"' % sar_path + self.collectOutputNow(sar_command, sar_filename, + root_symlink=sar_filename) + +class DebianSar(Sar, DebianPlugin, UbuntuPlugin): + """ Collect system activity reporter data + """ + + sa_path = '/var/log/sysstat' -- cgit