mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Merge pull request #881 from maticnetwork/DEVOPS-829/prometheus-metrics-format
DEVOPS-829 format fix for prometheus metrics
This commit is contained in:
commit
f1c8226839
2 changed files with 35 additions and 10 deletions
|
|
@ -30,6 +30,7 @@ var (
|
||||||
typeCounterTpl = "# TYPE %s counter\n"
|
typeCounterTpl = "# TYPE %s counter\n"
|
||||||
typeSummaryTpl = "# TYPE %s summary\n"
|
typeSummaryTpl = "# TYPE %s summary\n"
|
||||||
keyValueTpl = "%s %v\n\n"
|
keyValueTpl = "%s %v\n\n"
|
||||||
|
keyCounterTpl = "%s %v\n"
|
||||||
keyQuantileTagValueTpl = "%s {quantile=\"%s\"} %v\n"
|
keyQuantileTagValueTpl = "%s {quantile=\"%s\"} %v\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -61,11 +62,16 @@ func (c *collector) addGaugeFloat64(name string, m metrics.GaugeFloat64) {
|
||||||
func (c *collector) addHistogram(name string, m metrics.Histogram) {
|
func (c *collector) addHistogram(name string, m metrics.Histogram) {
|
||||||
pv := []float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999}
|
pv := []float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999}
|
||||||
ps := m.Percentiles(pv)
|
ps := m.Percentiles(pv)
|
||||||
c.writeSummaryCounter(name, m.Count())
|
|
||||||
|
var sum float64 = 0
|
||||||
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
|
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
|
||||||
for i := range pv {
|
for i := range pv {
|
||||||
c.writeSummaryPercentile(name, strconv.FormatFloat(pv[i], 'f', -1, 64), ps[i])
|
c.writeSummaryPercentile(name, strconv.FormatFloat(pv[i], 'f', -1, 64), ps[i])
|
||||||
|
sum += ps[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.writeSummarySum(name, fmt.Sprintf("%f", sum))
|
||||||
|
c.writeSummaryCounter(name, len(ps))
|
||||||
c.buff.WriteRune('\n')
|
c.buff.WriteRune('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,7 +82,7 @@ func (c *collector) addMeter(name string, m metrics.Meter) {
|
||||||
func (c *collector) addTimer(name string, m metrics.Timer) {
|
func (c *collector) addTimer(name string, m metrics.Timer) {
|
||||||
pv := []float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999}
|
pv := []float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999}
|
||||||
ps := m.Percentiles(pv)
|
ps := m.Percentiles(pv)
|
||||||
c.writeSummaryCounter(name, m.Count())
|
c.writeCounter(name, m.Count())
|
||||||
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
|
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
|
||||||
for i := range pv {
|
for i := range pv {
|
||||||
c.writeSummaryPercentile(name, strconv.FormatFloat(pv[i], 'f', -1, 64), ps[i])
|
c.writeSummaryPercentile(name, strconv.FormatFloat(pv[i], 'f', -1, 64), ps[i])
|
||||||
|
|
@ -90,11 +96,19 @@ func (c *collector) addResettingTimer(name string, m metrics.ResettingTimer) {
|
||||||
}
|
}
|
||||||
ps := m.Percentiles([]float64{50, 95, 99})
|
ps := m.Percentiles([]float64{50, 95, 99})
|
||||||
val := m.Values()
|
val := m.Values()
|
||||||
c.writeSummaryCounter(name, len(val))
|
|
||||||
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
|
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
|
||||||
c.writeSummaryPercentile(name, "0.50", ps[0])
|
c.writeSummaryPercentile(name, "0.50", ps[0])
|
||||||
c.writeSummaryPercentile(name, "0.95", ps[1])
|
c.writeSummaryPercentile(name, "0.95", ps[1])
|
||||||
c.writeSummaryPercentile(name, "0.99", ps[2])
|
c.writeSummaryPercentile(name, "0.99", ps[2])
|
||||||
|
|
||||||
|
var sum int64 = 0
|
||||||
|
|
||||||
|
for _, v := range val {
|
||||||
|
sum += v
|
||||||
|
}
|
||||||
|
|
||||||
|
c.writeSummarySum(name, fmt.Sprintf("%d", sum))
|
||||||
|
c.writeSummaryCounter(name, len(val))
|
||||||
c.buff.WriteRune('\n')
|
c.buff.WriteRune('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,17 +118,27 @@ func (c *collector) writeGaugeCounter(name string, value interface{}) {
|
||||||
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
|
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) writeSummaryCounter(name string, value interface{}) {
|
func (c *collector) writeCounter(name string, value interface{}) {
|
||||||
name = mutateKey(name + "_count")
|
name = mutateKey(name + "_count")
|
||||||
c.buff.WriteString(fmt.Sprintf(typeCounterTpl, name))
|
c.buff.WriteString(fmt.Sprintf(typeCounterTpl, name))
|
||||||
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
|
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *collector) writeSummaryCounter(name string, value interface{}) {
|
||||||
|
name = mutateKey(name + "_count")
|
||||||
|
c.buff.WriteString(fmt.Sprintf(keyCounterTpl, name, value))
|
||||||
|
}
|
||||||
|
|
||||||
func (c *collector) writeSummaryPercentile(name, p string, value interface{}) {
|
func (c *collector) writeSummaryPercentile(name, p string, value interface{}) {
|
||||||
name = mutateKey(name)
|
name = mutateKey(name)
|
||||||
c.buff.WriteString(fmt.Sprintf(keyQuantileTagValueTpl, name, p, value))
|
c.buff.WriteString(fmt.Sprintf(keyQuantileTagValueTpl, name, p, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *collector) writeSummarySum(name string, value string) {
|
||||||
|
name = mutateKey(name + "_sum")
|
||||||
|
c.buff.WriteString(fmt.Sprintf(keyCounterTpl, name, value))
|
||||||
|
}
|
||||||
|
|
||||||
func mutateKey(key string) string {
|
func mutateKey(key string) string {
|
||||||
return strings.Replace(key, "/", "_", -1)
|
return strings.Replace(key, "/", "_", -1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,6 @@ test_gauge 23456
|
||||||
# TYPE test_gauge_float64 gauge
|
# TYPE test_gauge_float64 gauge
|
||||||
test_gauge_float64 34567.89
|
test_gauge_float64 34567.89
|
||||||
|
|
||||||
# TYPE test_histogram_count counter
|
|
||||||
test_histogram_count 0
|
|
||||||
|
|
||||||
# TYPE test_histogram summary
|
# TYPE test_histogram summary
|
||||||
test_histogram {quantile="0.5"} 0
|
test_histogram {quantile="0.5"} 0
|
||||||
test_histogram {quantile="0.75"} 0
|
test_histogram {quantile="0.75"} 0
|
||||||
|
|
@ -77,6 +74,8 @@ test_histogram {quantile="0.95"} 0
|
||||||
test_histogram {quantile="0.99"} 0
|
test_histogram {quantile="0.99"} 0
|
||||||
test_histogram {quantile="0.999"} 0
|
test_histogram {quantile="0.999"} 0
|
||||||
test_histogram {quantile="0.9999"} 0
|
test_histogram {quantile="0.9999"} 0
|
||||||
|
test_histogram_sum 0.000000
|
||||||
|
test_histogram_count 6
|
||||||
|
|
||||||
# TYPE test_meter gauge
|
# TYPE test_meter gauge
|
||||||
test_meter 9999999
|
test_meter 9999999
|
||||||
|
|
@ -92,15 +91,17 @@ test_timer {quantile="0.99"} 1.2e+08
|
||||||
test_timer {quantile="0.999"} 1.2e+08
|
test_timer {quantile="0.999"} 1.2e+08
|
||||||
test_timer {quantile="0.9999"} 1.2e+08
|
test_timer {quantile="0.9999"} 1.2e+08
|
||||||
|
|
||||||
# TYPE test_resetting_timer_count counter
|
|
||||||
test_resetting_timer_count 6
|
|
||||||
|
|
||||||
# TYPE test_resetting_timer summary
|
# TYPE test_resetting_timer summary
|
||||||
test_resetting_timer {quantile="0.50"} 12000000
|
test_resetting_timer {quantile="0.50"} 12000000
|
||||||
test_resetting_timer {quantile="0.95"} 120000000
|
test_resetting_timer {quantile="0.95"} 120000000
|
||||||
test_resetting_timer {quantile="0.99"} 120000000
|
test_resetting_timer {quantile="0.99"} 120000000
|
||||||
|
test_resetting_timer_sum 180000000
|
||||||
|
test_resetting_timer_count 6
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
|
c.addResettingTimer("test/empty_resetting_timer", emptyResettingTimer)
|
||||||
|
|
||||||
exp := c.buff.String()
|
exp := c.buff.String()
|
||||||
if exp != expectedOutput {
|
if exp != expectedOutput {
|
||||||
t.Log("Expected Output:\n", expectedOutput)
|
t.Log("Expected Output:\n", expectedOutput)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue