From b9f1652800d7dc171d9fb3acb580bf6410401c66 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 13 Aug 2019 13:24:46 +0300 Subject: [PATCH] Marshal integer `*_sum` metric for Summary without scientific notation --- gauge.go | 2 +- summary.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gauge.go b/gauge.go index 4b93da1..ff2bda5 100644 --- a/gauge.go +++ b/gauge.go @@ -37,7 +37,7 @@ func (g *Gauge) Get() float64 { func (g *Gauge) marshalTo(prefix string, w io.Writer) { v := g.f() if float64(int64(v)) == v { - // Marshal integer values without scientific notations + // Marshal integer values without scientific notation fmt.Fprintf(w, "%s %d\n", prefix, int64(v)) } else { fmt.Fprintf(w, "%s %g\n", prefix, v) diff --git a/summary.go b/summary.go index def1f4e..509ce4a 100644 --- a/summary.go +++ b/summary.go @@ -109,7 +109,12 @@ func (sm *Summary) marshalTo(prefix string, w io.Writer) { if count > 0 { name, filters := splitMetricName(prefix) - fmt.Fprintf(w, "%s_sum%s %g\n", name, filters, sum) + if float64(int64(sum)) == sum { + // Marshal integer sum without scientific notation + fmt.Fprintf(w, "%s_sum%s %d\n", name, filters, int64(sum)) + } else { + fmt.Fprintf(w, "%s_sum%s %g\n", name, filters, sum) + } fmt.Fprintf(w, "%s_count%s %d\n", name, filters, count) } }