prometheus / prometheus/client_python

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

未关闭
#926 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
4.4k
派生
876
平均合并
8 天 4 小时
30 天内合并 PR
1

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先从 issue 中所示的 NGINX location 块和 Prometheus scrape target 配置开始,然后将 Unix domain socket 设置与正常工作的 Gunicorn TCP 设置进行比较。确定 metrics endpoint 是否支持此部署路径,并记录经过验证的配置或所需的限制。

由索引模型根据 Issue 内容生成。

评估

技术栈
nginx, python
领域
backend, networking, observability
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。