(self)
return queue_stats
Execute passenger-stats, parse its output, returnand requests in queue
Execute passenger-stats, parse its output, returnand requests in queue
Execute passenger - stats parse its output returnand requests in queue
def get_passenger_queue_stats(self):
        """
        Execute passenger-stats, parse its output, returnand requests in queue
        """
        queue_stats = {
            "top_level_queue_size": 0.0,
            "passenger_queue_size": 0.0,
        }

        command = [self.config["passenger_status_bin"]]
        if str_to_bool(self.config["use_sudo"]):
            command.insert(0, self.config["sudo_cmd"])

        try:
            proc1 = subprocess.Popen(command, stdout=subprocess.PIPE)
            (std_out, std_err) = proc1.communicate()

        except OSError:
            return {}

        if std_out is None:
            return {}

        re_colour = re.compile("\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]")
        re_requests = re.compile(r"Requests")
        re_topqueue = re.compile(r"^top-level")

        gen_info_flag = 0
        app_groups_flag = 0
        for raw_line in std_out.splitlines():
            line = re_colour.sub("", raw_line)
            if "General information" in line:
                gen_info_flag = 1
            if "Application groups" in line:
                app_groups_flag = 1
            elif re_requests.match(line) and re_topqueue.search(line):
                # If line starts with Requests and line has top-level queue then
                # store queue size
                line_splitted = line.split()
                if gen_info_flag == 1 and line_splitted:
                    queue_stats["top_level_queue_size"] = float(
                        line_splitted[5])
            elif re_requests.search(line) and not re_topqueue.search(line):
                # If line has Requests and nothing else special
                line_splitted = line.split()
                if app_groups_flag == 1 and line_splitted:
                    queue_stats["passenger_queue_size"] = float(
                        line_splitted[3])

        return queue_stats
def get_passenger_queue_stats ( self ) : queue_stats = { "top_level_queue_size" : 0.0 , "passenger_queue_size" : 0.0 , } command = [ self . config [ "passenger_status_bin" ] ] if str_to_bool ( self . config [ "use_sudo" ] ) : command . insert ( 0 , self . config [ "sudo_cmd" ] ) try : proc1 = subprocess . Popen ( command , stdout = subprocess . PIPE ) ( std_out , std_err ) = proc1 . communicate ( ) except OSError : return { } if std_out is None : return { } re_colour = re . compile ( "\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]" ) re_requests = re . compile ( r"Requests" ) re_topqueue = re . compile ( r"^top-level" ) gen_info_flag = 0 app_groups_flag = 0 for raw_line in std_out . splitlines ( ) : line = re_colour . sub ( "" , raw_line ) if "General information" in line : gen_info_flag = 1 if "Application groups" in line : app_groups_flag = 1 elif re_requests . match ( line ) and re_topqueue . search ( line ) : # If line starts with Requests and line has top-level queue then # store queue size line_splitted = line . split ( ) if gen_info_flag == 1 and line_splitted : queue_stats [ "top_level_queue_size" ] = float ( line_splitted [ 5 ] ) elif re_requests . search ( line ) and not re_topqueue . search ( line ) : # If line has Requests and nothing else special line_splitted = line . split ( ) if app_groups_flag == 1 and line_splitted : queue_stats [ "passenger_queue_size" ] = float ( line_splitted [ 3 ] ) return queue_stats