波前波形库
wavefront-pyformance的Python项目详细描述
波前性能
这是一个用于pyformance的插件,它添加了wavefront报告器(通过代理或直接接收)和一个支持主机级标记的抽象。它还包括对波前增量计数器的支持。
要求
支持Python2.7+和Python3.x。
pip install wavefront-pyformance
用法
波前报告器
Wavefront记者支持在主机级别进行标记。在发送到Wavefront之前,传递给报告者的标签将应用于每个度量。
创建波前报告器
您可以创建一个WavefrontProxyReporter
或WavefrontDirectReporter
,如下所示:
importpyformancefromwavefront_pyformanceimportwavefront_reporterreg=pyformance.MetricsRegistry()# report metrics to a Wavefront proxy every 10swf_proxy_reporter=wavefront_reporter.WavefrontProxyReporter(host=host,port=2878,registry=reg,source='wavefront-pyformance-example',tags={'key1':'val1','key2':'val2'},prefix='python.proxy.',reporting_interval=10)wf_proxy_reporter.start()# report metrics directly to a Wavefront server every 10swf_direct_reporter=wavefront_reporter.WavefrontDirectReporter(server=server,token=token,registry=reg,source='wavefront-pyformance-exmaple',tags={'key1':'val1','key2':'val2'},prefix='python.direct.',reporting_interval=10)wf_direct_reporter.start()
冲洗并停止Wavefront Reporter
创建波前报告程序后,start()
将使报告程序每隔reporting_interval
秒自动报告。
除此之外,您还可以调用report_now()
立即执行报告。report_now()
在停止报告程序之前,还应按如下方式调用:
wf_reporter.report_now()wf_reporter.stop()
增量计数器
要创建波前增量计数器:
importpyformancefromwavefront_pyformanceimportdeltareg=pyformance.MetricsRegistry()d_0=delta.delta_counter(reg,'requests_delta')d_0.inc(10)
注意:对任何两种类型的度量使用相同的度量名称将导致服务器上只有一个时间序列,从而导致冲突。 一般来说,所有度量名称都应该不同。如果有要作为计数器和增量计数器跟踪的度量,请考虑向其中一个度量添加相关后缀,以区分一个度量名称与另一个度量名称。
波前直方图
importpyformancefromwavefront_pyformanceimportwavefront_histogramreg=pyformance.MetricsRegistry()h_0=wavefront_histogram.wavefront_histogram(reg,'requests_duration')h_0.add(10)