Run Flower
master5555.repository·master·Indexed 27 days ago
https://github.com/mher/flowerFlower is an open-source web application for real-time monitoring and management of Celery clusters. It provides a web interface and REST API to view task progress, control worker instances, and monitor broker statistics. Key features include a Tasks API for managing asynchronous tasks, a Worker API for controlling worker pools and consumers, and support for multiple authentication methods including HTTP Basic Auth and OAuth2 providers such as Google, GitHub, GitLab, and Okta.
5555.Flower allows filtering tasks by various attributes including worker, type, state, and datetime. You can also filter by the values of args, kwargs, result, or state using a GitHub-style syntax.
If a search term contains spaces, you must enclose it in double quotes (e.g., args:"hello world").
To enable Google OAuth, you must first create a Web application credential in the Google Developer Console and obtain a Client ID and Client Secret. Add your redirect URI to the Authorized redirect URIs in the Google console.
Set the following configuration options:
auth_provider: Set to flower.views.auth.GoogleAuth2LoginHandlerauth: A pattern to allow specific emails (e.g., allowed-emails.*@gmail.com)oauth2_key: Your Google Client IDoauth2_secret: Your Google Client Secretoauth2_redirect_uri: The URI configured in Google consoleauth_provider="flower.views.auth.GoogleAuth2LoginHandler"
auth="allowed-emails.*@gmail.com"
oauth2_key="<your_client_id>"
oauth2_secret="<your_client_secret>"
oauth2_redirect_uri="http://localhost:5555/login"To retrieve information about queues, Flower uses the RabbitMQ Management Plugin. You must provide the URL of the RabbitMQ HTTP API via the --broker-api option.
Note: You must first enable the plugin on your RabbitMQ server:
$ rabbitmq-plugins enable rabbitmq_managementFLOWER_UNAUTHENTICATED_API environment variable to true.Follow these steps to set up a complete Celery monitoring stack using Docker.
docker run --name redis -d -p 6379:6379 redisEnsure your Celery application is configured to send events using the -E flag. This is required for Prometheus metrics.
Create a celeryconfig.py:
broker_url = 'redis://localhost:6379/0'
celery_result_backend = 'redis://localhost:6379/0'Start the worker:
celery -A tasks worker -l INFO -ERun Flower from your Celery application folder:
celery -A tasks --broker=redis://localhost:6379/0 flowerCreate a prometheus.yml file with the flower job (see Prometheus Configuration) and run:
docker run --name Prometheus -v <ABSOLUTE_PATH_TO_PROMETHEUS_YML>:/etc/prometheus/prometheus.yml -p 9090:9090 --network host prom/prometheusdocker run --name Grafana -d -v grafana-storage:/var/lib/grafana -p 3000:3000 --network host grafana/grafanaTo enable Okta OAuth, register Flower in Okta.
Set the following configuration options:
auth_provider: Set to flower.views.auth.OktaLoginHandleroauth2_key: Your Okta Client IDoauth2_secret: Your Okta Client Secretoauth2_redirect_uri: Your configured redirect URIAdditionally, you must set the following environment variable:
FLOWER_OAUTH2_OKTA_BASE_URL: Your Okta base URLFlower should not be exposed to the public internet without authentication. You can secure the Flower instance using Nginx auth_basic with a htpasswd file. Add the following lines to your location block in the Nginx configuration:
auth_basic "Restricted";
auth_basic_user_file htpasswd;You can install Flower using pip. To install the development version, you can install directly from the GitHub repository.
$ pip install flower
# Development version
$ pip install https://github.com/mher/flower/zipball/master#egg=flowerFlower operates as a sub-command of Celery. You can pass Celery configuration options immediately after the celery command and Flower-specific options after the flower sub-command. The syntax follows the pattern: celery [celery options] flower [flower options].
$ celery --broker=redis:// flower --unix-socket=/tmp/flower.sockYou can pass standard Celery configuration options (like --broker) to Flower. These options must be placed after the Celery application path (-A proj) but before the flower sub-command.
$ celery -A proj --broker=amqp://guest:guest@localhost:5672// flowerBy default, Flower attempts to load configuration from a file named flowerconfig.py. This file should be a standard Python file containing key-value pairs. You can specify a custom configuration file path using the conf option.
# Set RabbitMQ management api
broker_api = 'http://guest:guest@localhost:15672/api/'
# Enable debug logging
logging = 'DEBUG'