(self, dict_stats)
return overall_cpu
Execute % top; and return STDOUT.
Execute % top; and return STDOUT.
Execute % top ; and return STDOUT .
def get_passenger_cpu_usage(self, dict_stats):
        """
        Execute % top; and return STDOUT.
        """
        try:
            proc1 = subprocess.Popen(
                ["top", "-b", "-n", "2"],
                stdout=subprocess.PIPE)
            (std_out, std_err) = proc1.communicate()
        except OSError:
            return (-1)

        re_lspaces = re.compile("^\s*")
        re_digit = re.compile("^\d")
        overall_cpu = 0
        for raw_line in std_out.splitlines():
            line = re_lspaces.sub("", raw_line)
            if not re_digit.match(line):
                continue

            line_splitted = line.split()
            if line_splitted[0] in dict_stats["apache_procs"]:
                overall_cpu += float(line_splitted[8])
            elif line_splitted[0] in dict_stats["nginx_procs"]:
                overall_cpu += float(line_splitted[8])
            elif line_splitted[0] in dict_stats["passenger_procs"]:
                overall_cpu += float(line_splitted[8])

        return overall_cpu
def get_passenger_cpu_usage ( self , dict_stats ) : try : proc1 = subprocess . Popen ( [ "top" , "-b" , "-n" , "2" ] , stdout = subprocess . PIPE ) ( std_out , std_err ) = proc1 . communicate ( ) except OSError : return ( - 1 ) re_lspaces = re . compile ( "^\s*" ) re_digit = re . compile ( "^\d" ) overall_cpu = 0 for raw_line in std_out . splitlines ( ) : line = re_lspaces . sub ( "" , raw_line ) if not re_digit . match ( line ) : continue line_splitted = line . split ( ) if line_splitted [ 0 ] in dict_stats [ "apache_procs" ] : overall_cpu += float ( line_splitted [ 8 ] ) elif line_splitted [ 0 ] in dict_stats [ "nginx_procs" ] : overall_cpu += float ( line_splitted [ 8 ] ) elif line_splitted [ 0 ] in dict_stats [ "passenger_procs" ] : overall_cpu += float ( line_splitted [ 8 ] ) return overall_cpu