in metricbeat/helper/openmetrics/metric.go [212:322]
func (m *commonMetric) GetValue(metric *prometheus.OpenMetric) interface{} {
info := metric.GetInfo()
if info != nil {
if info.HasValidValue() {
return info.GetValue()
}
}
stateset := metric.GetStateset()
if stateset != nil {
if stateset.HasValidValue() {
return stateset.GetValue()
}
}
unknown := metric.GetUnknown()
if unknown != nil {
if !math.IsNaN(unknown.GetValue()) && !math.IsInf(unknown.GetValue(), 0) {
return int64(unknown.GetValue())
}
}
counter := metric.GetCounter()
if counter != nil {
if !math.IsNaN(counter.GetValue()) && !math.IsInf(counter.GetValue(), 0) {
return int64(counter.GetValue())
}
}
gauge := metric.GetGauge()
if gauge != nil {
if !math.IsNaN(gauge.GetValue()) && !math.IsInf(gauge.GetValue(), 0) {
return gauge.GetValue()
}
}
summary := metric.GetSummary()
if summary != nil {
value := mapstr.M{}
if !math.IsNaN(summary.GetSampleSum()) && !math.IsInf(summary.GetSampleSum(), 0) {
value["sum"] = summary.GetSampleSum()
value["count"] = summary.GetSampleCount()
}
quantiles := summary.GetQuantile()
percentileMap := mapstr.M{}
for _, quantile := range quantiles {
if !math.IsNaN(quantile.GetValue()) && !math.IsInf(quantile.GetValue(), 0) {
key := strconv.FormatFloat(100*quantile.GetQuantile(), 'f', -1, 64)
percentileMap[key] = quantile.GetValue()
}
}
if len(percentileMap) != 0 {
value["percentile"] = percentileMap
}
return value
}
histogram := metric.GetHistogram()
if histogram != nil {
value := mapstr.M{}
if !math.IsNaN(histogram.GetSampleSum()) && !math.IsInf(histogram.GetSampleSum(), 0) {
value["sum"] = histogram.GetSampleSum()
value["count"] = histogram.GetSampleCount()
}
buckets := histogram.GetBucket()
bucketMap := mapstr.M{}
for _, bucket := range buckets {
if bucket.GetCumulativeCount() != uint64(math.NaN()) && bucket.GetCumulativeCount() != uint64(math.Inf(0)) {
key := strconv.FormatFloat(bucket.GetUpperBound(), 'f', -1, 64)
bucketMap[key] = bucket.GetCumulativeCount()
}
}
if len(bucketMap) != 0 {
value["bucket"] = bucketMap
}
return value
}
gaugehistogram := metric.GetGaugeHistogram()
if gaugehistogram != nil {
value := mapstr.M{}
if !math.IsNaN(gaugehistogram.GetSampleSum()) && !math.IsInf(gaugehistogram.GetSampleSum(), 0) {
value["gsum"] = gaugehistogram.GetSampleSum()
value["gcount"] = gaugehistogram.GetSampleCount()
}
buckets := gaugehistogram.GetBucket()
bucketMap := mapstr.M{}
for _, bucket := range buckets {
if bucket.GetCumulativeCount() != uint64(math.NaN()) && bucket.GetCumulativeCount() != uint64(math.Inf(0)) {
key := strconv.FormatFloat(bucket.GetUpperBound(), 'f', -1, 64)
bucketMap[key] = bucket.GetCumulativeCount()
}
}
if len(bucketMap) != 0 {
value["bucket"] = bucketMap
}
return value
}
// Other types are not supported here
return nil
}