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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
burned42 opened this issue Dec 9, 2022 · 9 comments · Fixed by #57426
Closed

Comments

@burned42
Copy link
Contributor

burned42 commented Dec 9, 2022

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
@mahbodsh
Copy link

mahbodsh commented Dec 9, 2022

The idea is nice, thanks for your motivation to improve this grate framework. However, the main reason of showing the human readable output as a result of console command in the terminal is that we as human enter such commands to check sth meaningful for us.The idea of filtering the results based on the expected JSON keys "json | jq '.doctrine.count" is so cool and time saving possibility, but could be shorter and easier to write in comparison of represented one.

Best regards

Your fan, Mahbod

@xabbuh xabbuh added the Feature label Dec 12, 2022
@maxbeckers
Copy link
Contributor

Notice, the command is messenger:stats, was renamed during the PR #46571!

@burned42 burned42 changed the title [Messenger] Add machine readable (e.g. JSON) output format to messenger:count command [Messenger] Add machine readable (e.g. JSON) output format to messenger:stats command Dec 13, 2022
@burned42
Copy link
Contributor Author

burned42 commented Dec 13, 2022

@mahbodsh thanks for the feedback. Sure the idea for the current output is so that a human can execute the command and easily check the output. But my idea would be that in addition we have a machine readable output that we could use for automation, like said, e.g. for monitoring etc.

Let me outline the concrete use case I have so it's maybe a bit more clear what my intentions are. When I added the messenger to one of my applications, I built a command that just prints the number of messages in a given queue and I monitor that value with a monitoring system to detect when the queue gets full and maybe doesn't get processed, or not processed fast enough which might indicate an issue, or a need for more workers. The new messenger:stats command does mostly the same as my custom command, but the output is not really meant to be machine readable. Of course you could parse it somehow, but having a dedicated output format that is already easily parsable, like e.g. JSON would be really nice.

The idea of filtering the results based on the expected JSON keys "json | jq '.doctrine.count" is so cool and time saving possibility, but could be shorter and easier to write in comparison of represented one.

So for me it's not about saving time or having the shortest command, but rather to have an output tailored to use cases like the one outlined above. But it's just a suggestion, so if you have a better idea or some improvements, feel free to propose them :)


@maxbeckers thanks, you're right, I adjusted the title and description accordingly 👍 (I guess I just copy/pasted it from the original PR)

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

@xvilo
Copy link
Contributor

xvilo commented Jun 17, 2024

@carsonbot It would be great if you can reopen the issue. It seems there is still not a possibility for a machine readable out of the messenger transport statistics.

My use case would be to integrate this with the exec input of Telegraf, this allows us to send such statistics to for example Influx.

@xabbuh
Copy link
Member

xabbuh commented Jun 17, 2024

It looks like this issue is stalled as nobody started working on it. The best way to revive it would be to create a pull request implementing the wanted feature.

@xvilo
Copy link
Contributor

xvilo commented Jun 17, 2024

I'll see if I can make a PR soon with json output

fabpot added a commit that referenced this issue Jun 25, 2024
…ats` command (xvilo)

This PR was squashed before being merged into the 7.2 branch.

Discussion
----------

[Messenger] Add `--format` option to the `messenger:stats` command

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        | Fix #48583 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT

As requested in #48583 add a way to output different in formats for `messenger:stats` command. This can be more easily used in, for example, `jq` or with external automations/scripts and such.

Considerations I made:
- To not, yet, make different classes for the output. In case a new output format is added this might be handy.
- To not use an enum for output format, do we want this?
- To ignore warnings for now, except for the `uncountable_transports`. If we want to warning in there, what format?

Commits
-------

0e9f458 [Messenger] Add `--format` option to the `messenger:stats` command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants