我正在尝试使用sanic based向pyformance metrics library应用程序添加指标。
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个工作程序时,一切看起来都很好,但是当配置更多的工作程序时,不会将任何指标发送给碳。
我们非常感谢您的帮助,也提供了不同的方法,可以通过多工正常应用向石墨发送度量标准。
答案 0 :(得分:0)
因此,多个工作人员将基本上对工作人员进行子处理,这可能是IPC回到主流程的原因。
尝试根据此操作运行多个工作器,看看是否仍然存在相同的行为? How to configure ExecStart for Gunicorn without WSGI?
在这里,gunicorn负责管理流程。