当前位置: 首页>>代码示例>>Python>>正文


Python prometheus_client.make_wsgi_app方法代码示例

本文整理汇总了Python中prometheus_client.make_wsgi_app方法的典型用法代码示例。如果您正苦于以下问题:Python prometheus_client.make_wsgi_app方法的具体用法?Python prometheus_client.make_wsgi_app怎么用?Python prometheus_client.make_wsgi_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prometheus_client的用法示例。


在下文中一共展示了prometheus_client.make_wsgi_app方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validate_metrics

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import make_wsgi_app [as 别名]
def validate_metrics(self, metric_name, help_text, increments):
        """
        WSGI app serves the metrics from the provided registry.
        """
        c = Counter(metric_name, help_text, registry=self.registry)
        for _ in range(increments):
            c.inc()
        # Create and run WSGI app
        app = make_wsgi_app(self.registry)
        outputs = app(self.environ, self.capture)
        # Assert outputs
        self.assertEqual(len(outputs), 1)
        output = outputs[0].decode('utf8')
        # Status code
        self.assertEqual(self.captured_status, "200 OK")
        # Headers
        self.assertEqual(len(self.captured_headers), 1)
        self.assertEqual(self.captured_headers[0], ("Content-Type", CONTENT_TYPE_LATEST))
        # Body
        self.assertIn("# HELP " + metric_name + "_total " + help_text + "\n", output)
        self.assertIn("# TYPE " + metric_name + "_total counter\n", output)
        self.assertIn(metric_name + "_total " + str(increments) + ".0\n", output) 
开发者ID:prometheus,项目名称:client_python,代码行数:24,代码来源:test_wsgi.py

示例2: app

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import make_wsgi_app [as 别名]
def app(environ, start_fn):
    REQUESTS.inc()
    if environ['PATH_INFO'] == '/metrics':
        registry = CollectorRegistry()
        multiprocess.MultiProcessCollector(registry)
        metrics_app = make_wsgi_app(registry)
        return metrics_app(environ, start_fn)
    start_fn('200 OK', [])
    return [b'Hello World'] 
开发者ID:prometheus-up-and-running,项目名称:examples,代码行数:11,代码来源:4-4-app.py

示例3: _add_promethueus_middleware

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import make_wsgi_app [as 别名]
def _add_promethueus_middleware(app):
    # Add prometheus wsgi middleware to route /metrics requests
    # application object is then used by wsgi / gunicorn to startup the application
    # NOTE: This means prometheus metrics are not exposed in development mode
    wsgi_app = DispatcherMiddleware(app, {
        '/metrics': make_wsgi_app()
    })
    return wsgi_app 
开发者ID:hashedin,项目名称:squealy,代码行数:10,代码来源:__init__.py

示例4: create_app

# 需要导入模块: import prometheus_client [as 别名]
# 或者: from prometheus_client import make_wsgi_app [as 别名]
def create_app(config: CollectorConfig):

    app = Flask(__name__, instance_relative_config=True)

    client = AcsClient(
        ak=config.credential['access_key_id'],
        secret=config.credential['access_key_secret'],
        region_id=config.credential['region_id']
    )

    @app.route("/")
    def projectIndex():
        req = QueryProjectMetaRequest()
        req.set_PageSize(100)
        try:
            resp = client.do_action_with_exception(req)
        except Exception as e:
            return render_template("error.html", errorMsg=e)
        data = json.loads(resp)
        return render_template("index.html", projects=data["Resources"]["Resource"])

    @app.route("/projects/<string:name>")
    def projectDetail(name):
        req = QueryMetricMetaRequest()
        req.set_PageSize(100)
        req.set_Project(name)
        try:
            resp = client.do_action_with_exception(req)
        except Exception as e:
            return render_template("error.html", errorMsg=e)
        data = json.loads(resp)
        return render_template("detail.html", metrics=data["Resources"]["Resource"], project=name)

    @app.route("/yaml/<string:name>")
    def projectYaml(name):
        req = QueryMetricMetaRequest()
        req.set_PageSize(100)
        req.set_Project(name)
        try:
            resp = client.do_action_with_exception(req)
        except Exception as e:
            return render_template("error.html", errorMsg=e)
        data = json.loads(resp)
        return render_template("yaml.html", metrics=data["Resources"]["Resource"], project=name)

    app.jinja_env.filters['formatmetric'] = format_metric
    app.jinja_env.filters['formatperiod'] = format_period

    app_dispatch = DispatcherMiddleware(app, {
        '/metrics': make_wsgi_app()
    })
    return app_dispatch 
开发者ID:aylei,项目名称:aliyun-exporter,代码行数:54,代码来源:web.py


注:本文中的prometheus_client.make_wsgi_app方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。