项目作者: rob-blackbourn

项目描述 :
A Python3 asyncio API for the RabbitMQ management plugin
高级语言: Python
项目地址: git://github.com/rob-blackbourn/jetblack-rabbitmqmon.git
创建时间: 2020-04-18T09:30:50Z
项目社区:https://github.com/rob-blackbourn/jetblack-rabbitmqmon

开源协议:

下载


gascode-rabbitmqmon

This is an asyncio RabbitMQ monitor API for Python3.7+.

It wraps the RabbitMQ management plugin REST api. This allows retrieving
metrics and peeking into the queues.

Status

This is work in progress, but is functional.

Installation

This can be installed with pip.

Multiple clients a supported and one must be selected. Choose one of:

  1. pip install gascode-rabbitmqmon[bareclient]

Or alternatively:

  1. pip install gascode-rabbitmqmon[aiohttp]

Usage

The following gets an overview using the bareclient.

  1. import asyncio
  2. from gascode_rabbitmqmon.monitor import Monitor
  3. from gascode_rabbitmqmon.clients.bareclient_requester import BareRequester
  4. async def main_async():
  5. mon = Monitor(
  6. BareRequester(
  7. 'http://mq.example.com:15672',
  8. 'admin',
  9. 'admins password'
  10. )
  11. )
  12. overview = await mon.overview()
  13. print(overview)
  14. if __name__ == '__main__':
  15. asyncio.run(main_async())

The follow explores a vhost using the aiohttp client.

  1. import asyncio
  2. from gascode_rabbitmqmon.monitor import Monitor
  3. from gascode_rabbitmqmon.clients.aiohttp_requester import AioHttpRequester
  4. async def main_async():
  5. mon = Monitor(
  6. AioHttpRequester(
  7. 'http://mq.example.com:15672',
  8. 'admin',
  9. 'admins password'
  10. )
  11. )
  12. vhosts = await mon.vhosts()
  13. for vhost in vhosts.values(): # vhost is a dict
  14. exchanges = await vhost.exchanges()
  15. for exchange in exchanges.values(): # exchanges is a dict
  16. print(exchange)
  17. # Objects can be refreshed to gather new metrics.
  18. await exchange.refresh()
  19. print(exchange)
  20. bindings = await exchange.bindings()
  21. for binding in bindings:
  22. print(binding)
  23. if __name__ == '__main__':
  24. asyncio.run(main_async())

The following gets some messages from an exchange using the bareclient.

  1. import asyncio
  2. from gascode_rabbitmqmon.monitor import Monitor
  3. from gascode_rabbitmqmon.clients.bareclient_requester import BareRequester
  4. async def main_async():
  5. mon = Monitor(
  6. BareRequester(
  7. 'http://mq.example.com:15672',
  8. 'admin',
  9. 'admins password'
  10. )
  11. )
  12. vhosts = await mon.vhosts()
  13. vhost = vhosts['/some-vhost']
  14. queues = await vhost.queues()
  15. queue = queues['some.queue']
  16. messages = await queue.get_messages()
  17. print(messages)
  18. if __name__ == '__main__':
  19. asyncio.run(main_async())