Need help with Python printing JSON output on one line

Need help with Python printing JSON output on one line
0

#1

I’m trying to fix a custom plugin for monitoring Passenger output and having issues getting the executable file to print the JSON on one line. I work on the infrastructure side so Python is not my strong point at this time.

Here’s the portion of the code that I’m trying to get to print the output on one line.

   # Max pool size
    match = re.search('Max pool size : (\d+)', out)
    if match:
        stats['Max pool size'] = int(match.group(1))
    self.checks_logger.debug('{"name": "passenger-status", "protocol_version": "1", "integration_version": "1.0.0", "metrics": [{ "event_type": "PassengerSample", "Max pool size": "%s",' % stats['Max pool size'])

    # App groups
    match = re.search('App groups    : (\d+)', out)
    if match:
        stats['App groups'] = int(match.group(1))
    self.checks_logger.debug('"App groups": "%s",' %
            stats['App groups'])

    # Processes
    match = re.search('Processes     : (\d+)', out)
    if match:
        stats['Processes'] = int(match.group(1))
    self.checks_logger.debug('"Processes": "%s",' %
            stats['Processes'])

   # Requests in top-level queue
    match = re.search('Requests in top-level queue : (\d+)', out)
    if match:
        stats['Requests in top-level queue'] = int(match.group(1))
    self.checks_logger.debug('"Requests in top-level queue": "%s",' %
            stats['Requests in top-level queue'])

    # Requests in queue
    match = re.search('Requests in queue: (\d+)', out)
    if match:
        stats['Requests in queue'] = int(match.group(1))
    self.checks_logger.debug('"Requests in queue": "%s"}]}' %
            stats['Requests in queue'])

    return stats

def run(self):
    stats = {}
    stats.update(self.get_passenger_status())
    return stats

if __name__ == "__main__":
import logging
logger = logging.getLogger("Passenger")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
passenger = Passenger(None, logger, None)
passenger.run()

Current output:

{“name”: “passenger-status”, “protocol_version”: “1”, “integration_version”: “1.0.0”, “metrics”: [{ “event_type”: “PassengerSample”, “Max pool size”: “4”,
“App groups”: “1”,
“Processes”: “2”,
“Requests in top-level queue”: “0”,
“Requests in queue”: “0”}]}

Desired output:

{“name”: “passenger-status”, “protocol_version”: “1”, “integration_version”: “1.0.0”, “metrics”: [{ “event_type”: “PassengerSample”, “Max pool size”: “4”, “App groups”: “1”, “Processes”: “2”, “Requests in top-level queue”: “0”, “Requests in queue”: “0”}]}

Where am I going wrong here!?