【发布时间】:2018-07-28 09:19:30
【问题描述】:
我正在尝试使用 pyformance metrics library 将指标添加到 sanic based 应用程序。
import random
import time
from sanic import Sanic
from sanic.response import json
from pyformance import MetricsRegistry
from pyformance.reporters.carbon_reporter import CarbonReporter
registry = MetricsRegistry()
__reporter__ = CarbonReporter(registry=registry,
reporting_interval=10,
prefix='sanic',
server='localhost',
port=2003)
__reporter__.start()
app = Sanic()
@app.route("/api/v1/foo", methods=["POST"])
def foo(request):
timer = registry.timer(".foo")
with timer.time():
time.sleep(random.randint(1, 2))
return json({"status": True})
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080, workers=1, access_log=False,
debug=False)
当运行 1 个 worker 时一切看起来都很好,但是当配置更多 worker 时,没有指标被发送到 carbon。
感谢任何帮助,以及从多工人 sanic 应用程序向石墨发送指标的不同方法。
【问题讨论】:
标签: python-3.x graphite-carbon sanic