zoukankan      html  css  js  c++  java
  • flask

    1.显示请求使用时间-使用gauge显示每次的请求时间

    [root@VM_0_111_centos exporters]# cat request_time.py |egrep -v '^#|^$'
    import prometheus_client
    from prometheus_client import Counter, Gauge
    from prometheus_client.core import CollectorRegistry
    from flask import Response, Flask
    import pycurl
    app = Flask(__name__)
    REGISTRY = CollectorRegistry(auto_describe=False)
    http_request_time = Gauge(
        "myhttp_request_time",
        "use gauge to demostrate how muny time the request.",
        registry=REGISTRY)
    @app.route('/metrics')
    def r_value():
        c = pycurl.Curl()
        c.setopt(c.URL, '10.0.0.111:55555/a.txt')
        c.setopt(c.CONNECTTIMEOUT, 3)
        c.setopt(c.TIMEOUT, 3)
        try:
            c.perform()
        except pycurl.error:
            http_code = 500
            http_total_time = 999
        else:
            http_code = c.getinfo(pycurl.HTTP_CODE)
            http_total_time = c.getinfo(pycurl.TOTAL_TIME)
        http_request_time.set(http_total_time)
        return Response(prometheus_client.generate_latest(REGISTRY),
                        mimetype="text/plain")
    @app.route('/')
    def index():
        return "Hello, Prometheus!"
    if __name__ == "__main__":
        app.run(host='0.0.0.0',port='29091',debug=True)

    复制:https://www.cnblogs.com/z-ye/p/12741652.html

               https://blog.csdn.net/specter11235/article/details/87927202

  • 相关阅读:
    html5传感器
    html5 canvas手写字代码(兼容手机端)
    PHP pdo单例模式连接数据库
    PHP变量回收
    PHP不过过滤防止xss攻击的方法
    jquery监听回车
    jquery预加载显示百分比
    创建自己的代码仓库
    Luxurious Houses
    Vasya the Hipster
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/13702733.html
Copyright © 2011-2022 走看看