Bogdanp / django_dramatiq

A Django app that integrates with Dramatiq.
https://dramatiq.io
Other
350 stars 77 forks source link

No dramatiq metrics in prometheus #104

Open Cuda-Chen opened 3 years ago

Cuda-Chen commented 3 years ago

I am using using django_dramatiq in Docker. Now I would like to export the prometheus metrics describe in https://dramatiq.io/advanced.html#prometheus-metrics However, when I tried to watch the metrics of dramatiq it only shows Django-specific metrics:

# HELP django_migrations_unapplied_total Multiprocess metric
# TYPE django_migrations_unapplied_total gauge
django_migrations_unapplied_total{connection="default",pid="19"} 0.0
django_migrations_unapplied_total{connection="default",pid="18"} 0.0
django_migrations_unapplied_total{connection="default",pid="8"} 0.0
django_migrations_unapplied_total{connection="default",pid="16"} 0.0
django_migrations_unapplied_total{connection="default",pid="11"} 0.0
django_migrations_unapplied_total{connection="default",pid="17"} 0.0
# HELP django_migrations_applied_total Multiprocess metric
# TYPE django_migrations_applied_total gauge
django_migrations_applied_total{connection="default",pid="19"} 36.0
django_migrations_applied_total{connection="default",pid="18"} 36.0
django_migrations_applied_total{connection="default",pid="8"} 36.0
django_migrations_applied_total{connection="default",pid="16"} 36.0
django_migrations_applied_total{connection="default",pid="11"} 36.0
django_migrations_applied_total{connection="default",pid="17"} 36.0

For further information, here are some settings of my app:

  1. settings.py
    
    # Just show dramatiq related settings

DRAMATIQ_BROKER = { "BROKER": "dramatiq.brokers.rabbitmq.RabbitmqBroker", "OPTIONS": { "url": "", }, "MIDDLEWARE": [ "dramatiq.middleware.Prometheus", "dramatiq.middleware.AgeLimit", "dramatiq.middleware.TimeLimit", "dramatiq.middleware.Callbacks", "dramatiq.middleware.Retries", "django_dramatiq.middleware.DbConnectionsMiddleware", "django_dramatiq.middleware.AdminMiddleware", ] }

DRAMATIQ_TASKS_DATABASE = "default"

MIDDLEWARE = [ 'django_prometheus.middleware.PrometheusBeforeMiddleware', 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django_prometheus.middleware.PrometheusAfterMiddleware', ]

2. `docker-compose.yml`
```yaml
# Just show worker related settings
worker:
    build: .
    init: true
    environment:
      - prometheus_multiproc_dir=/tmp/dramatiq-prometheus
      - dramatiq_prom_db=/tmp/dramatiq-prometheus
    command: bash -c "
      mkdir -p /tmp/dramatiq-prometheus
      && rm -rf /tmp/dramatiq-prometheus/*
      python manage.py migrate django_dramatiq 
      && python manage.py rundramatiq --threads 1"
    volumes:
      - .:/code
    ports:
      - "9191:9191"
    depends_on:
      - db
      - rabbitmq

Thanks for your help!

k578fgr commented 1 year ago

Hello! Can't understand why my prometheus have no dramatiq metrics Did you solve this problem?

Cuda-Chen commented 1 year ago

Can't understand why my prometheus have no dramatiq metrics

It means that Prometheus does not show any metrics of dramatiq.

Did you solve this problem?

I solve the problem. However, I opened this issue about two years ago, so I barely remember the way I solve this problem. If I do not remember anything wrong, I just forget to actually open the ports in my docker-compose settings.

k578fgr commented 1 year ago

@Cuda-Chen Do you have a repo of these code ?

Cuda-Chen commented 1 year ago

@k578fgr taking the following docker-compose.yml as example:

worker:
    # Use Dockerfile of your Django app
    build: . 

    environment:
      - dramatiq_prom_host=worker
      - dramatiq_prom_port=9191
      - prometheus_multiproc_dir=/tmp/dramatiq-prometheus
      - dramatiq_prom_db=/tmp/dramatiq-prometheus
      -
    command: bash -c "
      mkdir -p /tmp/dramatiq-prometheus
      && rm -rf /tmp/dramatiq-prometheus/*
      && python manage.py migrate django_dramatiq
      && python manage.py rundramatiq --threads 1"

    ports:
      - "9191:9191"

    depends_on:
      # I use rabbitmq as broker
      - rabbitmq