我阅读了Prometheus客户端的文档https://github.com/prometheus/client_python/#multiprocess-mode-gunicorn ,其中提到了在python中以多进程模式公开指标。我不是通过Gunicorn而是通过uwsgi运行django应用程序。与文档中的代码类似,我在项目的wsgi.py中添加了代码-
class WSGIEnvironment(WSGIHandler):
def __call__(self, environ, start_response):
**registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)**
django.setup()
return super(WSGIEnvironment, self).__call__(environ,
start_response)
application = WSGIEnvironment()
Run Code Online (Sandbox Code Playgroud)
但是通过这种方法公开收集的数据对我来说似乎并不可行。因此,我在Django应用程序/ metrics中公开了一个调用指标视图的api-
def metrics(request):
registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
print "data", data
return HttpResponse(
data,
content_type=CONTENT_TYPE_LATEST)
Run Code Online (Sandbox Code Playgroud)
我仍然无法查看我的应用程序公开的指标。是否需要任何配置?我想我缺少非常基本的东西。