Skip to content

Commit 90f8ebc

Browse files
Humanize metrics uptime
1 parent 80775ef commit 90f8ebc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

metrics/metrics.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
package metrics // import "github.com/wabarc/wayback/metrics"
66

77
import (
8-
"fmt"
98
"runtime"
109
"time"
1110

11+
"github.com/dustin/go-humanize"
1212
"github.com/prometheus/client_golang/prometheus"
1313
"github.com/wabarc/logger"
1414
"github.com/wabarc/wayback/version"
@@ -117,7 +117,7 @@ func NewCollector() *Collector {
117117
uptimeDesc: prometheus.NewDesc(
118118
"wayback_uptime",
119119
"The uptime of wayback service.",
120-
[]string{"duration"}, nil),
120+
[]string{"up"}, nil),
121121
}
122122
prometheus.MustRegister(collector)
123123
prometheus.MustRegister(buildInfoGauge)
@@ -141,8 +141,8 @@ func init() {
141141

142142
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
143143
// Set uptime
144-
duration := fmt.Sprint(time.Since(startTime).Truncate(time.Second))
145-
m, err := prometheus.NewConstMetric(c.uptimeDesc, prometheus.GaugeValue, float64(1), duration)
144+
uptime := humanize.Time(startTime)
145+
m, err := prometheus.NewConstMetric(c.uptimeDesc, prometheus.GaugeValue, float64(1), uptime)
146146
if err != nil {
147147
return err
148148
}

0 commit comments

Comments
 (0)