本文整理汇总了Golang中github.com/prometheus/client_golang/prometheus.SummaryVec类的典型用法代码示例。如果您正苦于以下问题:Golang SummaryVec类的具体用法?Golang SummaryVec怎么用?Golang SummaryVec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SummaryVec类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: timeRequestStatus
// timeRequestStatus runs 'f' and records how long it took in the given
// Prometheus metric.
//
// toStatusCode is a function that translates errors returned by 'f' into
// HTTP-like status codes.
func timeRequestStatus(method string, metric *prometheus.SummaryVec, toStatusCode func(error) string, f func() error) error {
if toStatusCode == nil {
toStatusCode = errorCode
}
startTime := time.Now()
err := f()
duration := time.Now().Sub(startTime)
metric.WithLabelValues(method, toStatusCode(err)).Observe(duration.Seconds())
return err
}
示例2: measureCommandDuration
func measureCommandDuration(m *prometheus.SummaryVec, fn func() error, labels ...string) error {
n := time.Now()
err := fn()
duration := time.Now().Sub(n)
statusCode, ok := exitCodeForCommandError(err)
if !ok {
statusCode = -1
}
m.WithLabelValues(append(labels, strconv.Itoa(statusCode))...).Observe(float64(duration / time.Millisecond))
return err
}
示例3: readSummaryVec
// TODO: Pending prometheus/client_golang#58
// read metric helpers needs rework once testability is improved!
func readSummaryVec(m *prometheus.SummaryVec, l prometheus.Labels) []*dto.Quantile {
pb := &dto.Metric{}
s := m.With(l)
s.Write(pb)
return pb.GetSummary().GetQuantile()
}