【问题标题】:promotheus monitoring a simple applicationprometheus 监控一个简单的应用
【发布时间】:2018-05-11 08:16:58
【问题描述】:

我正在尝试使用 prometheus 监控一个简单的应用程序,但不知道从哪里开始。

我创建了一个简单的测试函数,它将休眠 10 秒,并使用 prometheus - 摘要指标进行跟踪。

from prometheus_client import Summary
import time
from datetime import datetime

TF_CALL_SUMMARY = Summary("call_seconds", "Time spent inside test function")

def test():

    while True:
        t1 = datetime.now()
            time.sleep(10)      
            t2 = datetime.now()
            delta = t2 - t1 
        TF_CALL_SUMMARY.observe(delta.total_seconds())
        print delta

print 'start application'
test()
print 'end application'

现在这不是一个可以有 /metric 端点​​的 Web 应用程序。

如何将此指标导出到我的 prometheus 服务器?

【问题讨论】:

    标签: prometheus


    【解决方案1】:

    您需要将数据公开给 Promethueus:

    from prometheus_client import start_http_server
    
    if __name__ == '__main__':
        start_http_server(8000)
    

    然后你需要configurePrometheus 来抓取这个数据源。在您的 Prometheus 配置文件中添加如下内容:

    # Prometheus.yml
    scrape_configs:
      - job: "python" 
        static_configs:
          - targets: ["localhost:8000"]
    

    这是一个tutorial,详细介绍了对您有用的 Python 应用程序的检测。

    【讨论】:

    • 每个应用都应该运行一个被监控的服务,对吗?
    • @user1050619 是的。来自Prometheus documentation:“Prometheus 是一个监控平台,它通过在这些目标上抓取指标 HTTP 端点来收集来自被监控目标的指标。”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 2022-11-04
    • 2020-05-21
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    相关资源
    最近更新 更多