Marshal integer *_sum metric for Summary without scientific notation

This commit is contained in:
Aliaksandr Valialkin 2019-08-13 13:24:46 +03:00
parent c68df4bc3d
commit b9f1652800
2 changed files with 7 additions and 2 deletions

View File

@ -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)

View File

@ -109,7 +109,12 @@ func (sm *Summary) marshalTo(prefix string, w io.Writer) {
if count > 0 {
name, filters := splitMetricName(prefix)
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)
}
}