Open SyperAlexKomp opened 9 months ago
If you have a repo to look at, or a (minimal?) example of the setup, we could try working out what's going wrong.
I am having the same issue. Here's a minimal example that I used to reproduce this:
import os
from flask import Flask
from gunicorn.app.base import BaseApplication
from prometheus_flask_exporter.multiprocess import GunicornInternalPrometheusMetrics
class StandaloneApplication(BaseApplication):
def __init__(self):
os.environ['PROMETHEUS_MULTIPROC_DIR'] = '/tmp'
self.application = Flask('my_app')
self.application.add_url_rule('/test', 'test', self.index)
self.metrics = GunicornInternalPrometheusMetrics(self.application)
super().__init__()
def load_config(self) -> None:
pass
def load(self):
return self.application
def index(self):
return 'Hello world'
StandaloneApplication().run()
Accessing the application via http://localhost:8000/test
works fine, but http://localhost:8000/metrics
yields an empty page.
I'm curious, what is the status code on the /metrics request? Is it 404 or 200 or something else?
It's 200
:
curl -v http://127.0.0.1:8000/metrics
* Trying 127.0.0.1:8000...
* Connected to 127.0.0.1 (127.0.0.1) port 8000
> GET /metrics HTTP/1.1
> Host: 127.0.0.1:8000
> User-Agent: curl/8.6.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: gunicorn
< Date: Tue, 02 Jul 2024 10:42:57 GMT
< Connection: close
< Content-Type: text/plain; version=0.0.4; charset=utf-8
< Content-Length: 0
<
* Closing connection
I am using:
I had a look now, it looks like the problem is that the PROMETHEUS_MULTIPROC_DIR
configuration happens too late.
If you run your app with PROMETHEUS_MULTIPROC_DIR=/tmp python3 app.py
then things work as expected.
If you move the os.environ['PROMETHEUS_MULTIPROC_DIR'] = '/tmp'
line right after the import os
line to line 2, then it also works, but that's less recommended.
Hope this helps!
Indeed, when setting the environment variable before importing the prometheus_flask_exporter
, it is working as expected.
Thanks for the quick help! 👍
I've done all the same as in the README.MD, but when I use one of GunicornInternalPrometheusMetrics or GunicornPrometheusMetrics - /metrics request returns empty response. I've tried everything. I'm starting gunicorn by systemctl. Also when I'm using PrometheusMetrics all is working fine. Maybe it's because systemctl?