gopfercounter提供了几种类型的统计器,分比为Gauge、Meter、Histogram。统计器的含义,参见java-metrics。
A gauge metric is an instantaneous reading of a particular value
- 接口: Gauge(name string, value int64)
- 参数: value - 记录的数值
- 例子:
Gauge("queueSize", int64(13))
- 接口: SetGaugeValue(name string, value float64)
- Alias: GaugeFloat64(name string, value float64)
- 参数: value - 记录的数值
- 例子:
GaugeFloat64("requestRate", float64(13.14))
SetGaugeValue("requestRate", float64(13.14))
- 接口: GetGaugeValue(name string) float64
- 例子:
reqRate := GetGaugeValue("requestRate")
A meter metric which measures mean throughput and one-, five-, and fifteen-minute exponentially-weighted moving average throughputs.
关于EWMA, 点击这里
- 接口: SetMeterCount(name string, value int64)
- Alias: Meter(name string, value int64)
- 参数: value - 该事件发生的次数
- 例子:
// 页面访问次数统计,每来一次访问,pv加1
SetMeterCount("pageView", int64(1))
- 接口: GetMeterCount(name string) int64
- 例子:
// 获取pv次数的总和
pvSum := GetMeterCount("pageView")
- 接口: GetMeterRateStep(name string) float64
- 例子:
// pv发生次数的时间平均,单位CPS。计时范围为,本接口两次调用的时间差,即一个上报周期。
pvRateStep := GetMeterRateStep("pageView")
- 接口: GetMeterRateMean(name string) float64
- 例子:
// pv发生次数的时间平均,单位CPS。计时范围为,goperfcounter完成初始,至当前时刻。
pvRateMean := GetMeterRateMean("pageView")
- 接口: GetMeterRate1(name string) float64
- 例子:
// pv发生次数的1min滑动平均值,单位CPS
pvRate1Min := GetMeterRate1("pageView")
- 接口: GetMeterRate5(name string) float64
- 例子:
// pv发生次数的5min滑动平均值,单位CPS
pvRate5Min := GetMeterRate5("pageView")
- 接口: GetMeterRate15(name string) float64
- 例子:
// pv发生次数的15min滑动平均值,单位CPS
pvRate15Min := GetMeterRate15("pageView")
A histogram measures the statistical distribution of values in a stream of data. In addition to minimum, maximum, mean, etc., it also measures median, 75th, 90th, 95th, 98th, and 99th percentiles
- 接口: SetHistogramCount(name string, count int64)
- Alias: Histogram(name string, count int64)
- 参数: count - 该记录当前采样点的取值
- 例子:
// 设置当前同时处理请求的并发度
SetHistogramCount("processNum", int64(325))
- 接口: GetHistogramMax(name string) int64
- 例子:
max := GetHistogramMax("processNum")
- 接口: GetHistogramMin(name string) int64
- 例子:
min := GetHistogramMin("processNum")
- 接口: GetHistogramMean(name string) float64
- 例子:
mean := GetHistogramMean("processNum")
- 接口: GetHistogram75th(name string) float64
- 例子:
// 获取所有采样数据中,处于75%的并发度
pNum75th := GetHistogram75th("processNum")
- 接口: GetHistogram95th(name string) float64
- 例子:
// 获取所有采样数据中,处于95%的并发度
pNum95th := GetHistogram95th("processNum")
- 接口: GetHistogram99th(name string) float64
- 例子:
// 获取所有采样数据中,处于99%的并发度
pNum99th := GetHistogram99th("processNum")