小编a_k*_*k_g的帖子

如何使用Prometheus客户端从作为uwsgi服务器运行的Django应用中导出应用指标?

我阅读了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)

我仍然无法查看我的应用程序公开的指标。是否需要任何配置?我想我缺少非常基本的东西。

python django uwsgi prometheus

7
推荐指数
1
解决办法
1217
查看次数

标签 统计

django ×1

prometheus ×1

python ×1

uwsgi ×1