本文整理汇总了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)
示例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']
示例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
示例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