Celery-管理與監控

1. 監控和管理Workers

1.1 將celery實例放入shell
[root@node2 app]# celery -A tasks shell
Python 3.6.5 (default, Oct 23 2019, 12:55:54) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: app                                                                                                                          
Out[1]: <Celery tasks at 0x7ff7dddbdc18>

In [2]: add.delay(1,2)                                                                                                               
Out[2]: <AsyncResult: c5cfd00f-8b11-4408-95e2-241f2f3d5521>
1.2 查看任務的結果
[root@node2 app]# celery -A tasks  result c5cfd00f-8b11-4408-95e2-241f2f3d5521
3

  

1.3 從全部已配置的任務隊列中清除消息
[root@node2 app]# celery -A tasks  purge
WARNING: This will remove all tasks from queue: celery.
         There is no undo for this operation!

(to skip this prompt use the -f option)

Are you sure you want to delete all tasks (yes/NO)? yes
No messages purged from 1 queue

  

您還可使用-Q選項指定要清除的隊列html

$ celery -A proj purge -Q celery,foo,bar

並使用-X選項排除清除隊列node

  $ celery -A proj purge -X celeryredis


1.4 列出活動的任務

  celery -A tasks inspect activeshell

1.5列出計劃的ETA任務

  celery -A tasks inspect scheduledbash

這些是設置etacountdown參數時由工做人員保留的任務 app

 

1.6 列出保留任務
  celery -A tasks inspect reserved

這將列出工做者已經預取的全部任務,而且當前正在等待執行(不包括設置了ETA值的任務)。ide

1.7 列出已撤銷任務的歷史記錄

  $ celery -A tasks inspect revokedui

1.8 列出註冊的任務
  celery -A tasks inspect registered

1.9 顯示worker的統計信息
   celery -A tasks inspect stats 
1.10 查詢任務信息

  celery -A tasks inspect query_task task_idthis

1.11啓用和禁用事件

  celery -A tasks control enable_events/disable_eventsspa

 

2. Flower: Celery實時的Web監控

2.1 安裝flower
pip install flower
2.2 啓動Flower
 celery -A tasks flower

 能夠添加--port參數指定監聽端口,默認監聽5555 

或者經過指定Broker URL
$ celery flower --broker=amqp://guest:guest@localhost:5672//
or
$ celery flower --broker=redis://guest:guest@localhost:6379/0

  

3. celery events: Curses Monitor

celery -A tasks events

能夠看件以下界面:

 

 按j,k鍵能夠選中task,查看任務結果

相關文章
相關標籤/搜索