Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No dramatiq metrics in prometheus #104

Closed
Cuda-Chen opened this issue May 7, 2021 · 5 comments
Closed

No dramatiq metrics in prometheus #104

Cuda-Chen opened this issue May 7, 2021 · 5 comments

Comments

@Cuda-Chen
Copy link

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": "<my RabbitMQ 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',
]
  1. docker-compose.yml
# 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
Copy link

k578fgr commented Jun 21, 2023

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

@Cuda-Chen
Copy link
Author

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
Copy link

k578fgr commented Jun 21, 2023

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

@Cuda-Chen
Copy link
Author

@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

@andrewgy8
Copy link
Collaborator

Hi @Cuda-Chen,

It looks like the issue has been resolved based on the latest comments. Since there has been no further activity, I’m going to close this PR for now. If the issue persists or if you need any further changes, feel free to reopen it or reach out.

Thanks for your work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants