prometheus / prometheus/client_python

In Django application, '/metrics' unaccessible when using Unix Domain Sockets

Open
#926 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.4k
Forks
876
Avg merge
8d 4h
Merged PRs (30d)
1

Description

Im using the django_prometheus library which is a wrapper for prometheus_client library for my Django app. I am not running Prometheus, (or the entire applcaition in a Docker container), which might be part of my problem, though I dont see why this would be a requirement. The Django application is bound to Unix Domain Sockets,. NGINX is listening on default port 80 and re-routes traffic with the proxy_pass header.

NGINX

server {
    server_name hotname www.hostname ip;

[...]
    location /metrics{

        proxy_pass http://<unix_domain_socket>;
    }

    location / {
        proxy_pass http://unix:<unix_domain_socket>;
        
}

prometheus

<default prom config>
[...]
    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "django-app"
    scrape_interval: 10s
    static_configs:
      - targets: ["localhost] # nothing works (IP, etc..) and prometheus attempts to use port 80 with a predefined scheme of http://

  - job_name: "node"
    scrape_interval: 10s
    static_configs:
      - targets: ["localhost:9100"]

Solution

By removing the unix domain socket in NGINX and going back to TCP/IP that gunicorn uses by default, Prometheus was able to successfully pickup metrics from /metrics

Is there something Im missing? I feel like the only other options are changing the whole infrastructure ( to docker), or try and use a log based-metrics.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the NGINX location blocks and Prometheus scrape target configuration shown in the issue, then compare the Unix domain socket setup with the working Gunicorn TCP setup. Determine whether the metrics endpoint supports this deployment path and document a verified configuration or the required limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx, python
Domain
backend, networking, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.