Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Add machine readable (e.g. JSON) output format to messenger:stats command #48583

Closed
@burned42

Description

@burned42

Description

The new messenger:stats (see #46571) command is nice to see how many messages are in your queues, but I think we can still improve that a bit. At the moment messenger:stats only supports printing the output to a nicely formatted table, which is fine if a human is reading the output, but it's not that machine-readable.

It would be nice to have the option to use some different output format, so you can get the message count in a machine-readable format that you could e.g. feed into a monitoring system, use it as part of a system for auto-scaling workers etc.

I can see that some other symfony commands support a --format argument with a default of text or similar, providing different output formats such as e.g. json, which could also be an option here.

Down below I prepared an example using JSON as output format.
Not sure how we could treat those 'uncountable transports' best. Maybe with an exit code other than 0 or setting the count to null.

So I'd like to hear your opinion on that. Would you like to see / use such a feature?

Example

# Print message counts as JSON
$ bin/console messenger:stats --format json
{"rabbitmq": 42, "doctrine": 23}
# Print message count for one transport
$ bin/console messenger:stats doctrine --format json
{"doctrine": 23}
# Example on how to work with the potential JSON output
$ bin/console messenger:stats --format json | jq '.doctrine'
23

In case we already think that maybe in future there will be more information to add for each transport, we could already make the values objects as well, but just have a count property for now to prevent BC break when adding more information, not sure if that's necessary, or too far-sighted already though 😅

$ bin/console messenger:stats --format json
{"rabbitmq": {"count": 42}, "doctrine": {"count": 23}}
$ bin/console messenger:stats doctrine --format json
{"doctrine": {"count": 23}}
$ bin/console messenger:stats --format json | jq '.doctrine.count'
23

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions