Flower Documentation

repository·master·Indexed 27 days ago

https://github.com/mher/flower

Flower 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.

Tokens
7K
Snippets
27
Records
51
Agent score
92%

What's inside Flower

  1. Filter tasks using GitHub-style syntax

    master

    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").

  2. Configure Google OAuth Authentication

    master

    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.GoogleAuth2LoginHandler
    • auth: A pattern to allow specific emails (e.g., allowed-emails.*@gmail.com)
    • oauth2_key: Your Google Client ID
    • oauth2_secret: Your Google Client Secret
    • oauth2_redirect_uri: The URI configured in Google console
    auth_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"
  3. Configure RabbitMQ Management API

    master

    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_management
  4. Enable the Flower API for unauthenticated environments

    master
    By default, the Flower API is disabled for security reasons if authentication is not enabled. To allow access to the API in unauthenticated environments, set the FLOWER_UNAUTHENTICATED_API environment variable to true.
  5. Full Stack Setup: Celery, Flower, Prometheus, and Grafana

    master

    Follow these steps to set up a complete Celery monitoring stack using Docker.

    1. Start Celery Broker (Redis)

    docker run --name redis -d -p 6379:6379 redis

    2. Set Up and Start Celery Application

    Ensure 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 -E

    3. Start Flower Monitoring

    Run Flower from your Celery application folder:

    celery -A tasks --broker=redis://localhost:6379/0 flower

    4. Configure and Start Prometheus

    Create 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/prometheus

    5. Start Grafana

    docker run --name Grafana -d -v grafana-storage:/var/lib/grafana -p 3000:3000 --network host grafana/grafana
  6. Configure Okta OAuth Authentication

    master

    To enable Okta OAuth, register Flower in Okta.

    Set the following configuration options:

    • auth_provider: Set to flower.views.auth.OktaLoginHandler
    • oauth2_key: Your Okta Client ID
    • oauth2_secret: Your Okta Client Secret
    • oauth2_redirect_uri: Your configured redirect URI

    Additionally, you must set the following environment variable:

    • FLOWER_OAUTH2_OKTA_BASE_URL: Your Okta base URL
  7. Secure Flower with Nginx Basic Authentication

    master

    Flower 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;
  8. Install Flower

    master

    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=flower
  9. Configure Flower via Command Line

    master

    Flower 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.sock
  10. Pass Broker URL and Celery options to Flower

    master

    You 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// flower
  11. Configure Flower using a Configuration File

    master

    By 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'