本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/util/metric.Registry.Each方法的典型用法代碼示例。如果您正苦於以下問題:Golang Registry.Each方法的具體用法?Golang Registry.Each怎麽用?Golang Registry.Each使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/pkg/util/metric.Registry
的用法示例。
在下文中一共展示了Registry.Each方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: eachRecordableValue
// eachRecordableValue visits each metric in the registry, calling the supplied
// function once for each recordable value represented by that metric. This is
// useful to expand certain metric types (such as histograms) into multiple
// recordable values.
func eachRecordableValue(reg *metric.Registry, fn func(string, float64)) {
reg.Each(func(name string, mtr interface{}) {
if histogram, ok := mtr.(*metric.Histogram); ok {
// TODO(mrtracy): Where should this comment go for better
// visibility?
//
// Proper support of Histograms for time series is difficult and
// likely not worth the trouble. Instead, we aggregate a windowed
// histogram at fixed quantiles. If the scraping window and the
// histogram's eviction duration are similar, this should give
// good results; if the two durations are very different, we either
// report stale results or report only the more recent data.
//
// Additionally, we can only aggregate max/min of the quantiles;
// roll-ups don't know that and so they will return mathematically
// nonsensical values, but that seems acceptable for the time
// being.
curr, _ := histogram.Windowed()
for _, pt := range recordHistogramQuantiles {
fn(name+pt.suffix, float64(curr.ValueAtQuantile(pt.quantile)))
}
} else {
val, err := extractValue(mtr)
if err != nil {
log.Warning(context.TODO(), err)
return
}
fn(name, val)
}
})
}