Skip to content

Commit

Permalink
Merge pull request #5 from zsais/register-errors
Browse files Browse the repository at this point in the history
handle multi-registration attempts and log errors
  • Loading branch information
zsais authored Jul 26, 2017
2 parents 9465035 + 15ca341 commit 718880c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)

var defaultMetricPath = "/metrics"
Expand Down Expand Up @@ -41,7 +42,12 @@ func (p *Prometheus) registerMetrics(subsystem string) {
},
[]string{"code", "method", "handler"},
)
prometheus.MustRegister(p.reqCnt)

if err := prometheus.Register(p.reqCnt); err != nil {
log.Info("reqCnt could not be registered: ", err)
} else {
log.Info("reqCnt registered.")
}

p.reqDur = prometheus.NewSummary(
prometheus.SummaryOpts{
Expand All @@ -50,7 +56,12 @@ func (p *Prometheus) registerMetrics(subsystem string) {
Help: "The HTTP request latencies in seconds.",
},
)
prometheus.MustRegister(p.reqDur)

if err := prometheus.Register(p.reqDur); err != nil {
log.Info("reqDur could not be registered: ", err)
} else {
log.Info("reqDur registered.")
}

p.reqSz = prometheus.NewSummary(
prometheus.SummaryOpts{
Expand All @@ -59,7 +70,12 @@ func (p *Prometheus) registerMetrics(subsystem string) {
Help: "The HTTP request sizes in bytes.",
},
)
prometheus.MustRegister(p.reqSz)

if err := prometheus.Register(p.reqSz); err != nil {
log.Info("reqSz could not be registered: ", err)
} else {
log.Info("reqSz registered.")
}

p.resSz = prometheus.NewSummary(
prometheus.SummaryOpts{
Expand All @@ -68,7 +84,12 @@ func (p *Prometheus) registerMetrics(subsystem string) {
Help: "The HTTP response sizes in bytes.",
},
)
prometheus.MustRegister(p.resSz)

if err := prometheus.Register(p.resSz); err != nil {
log.Info("resSz could not be registered: ", err)
} else {
log.Info("resSz registered.")
}

}

Expand Down

0 comments on commit 718880c

Please sign in to comment.