Skip to content

Commit

Permalink
Add default Golang metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniotsi committed Mar 30, 2023
1 parent 711c672 commit 1c30347
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"context"
"github.com/prometheus/client_golang/prometheus/collectors"
"net/http"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -167,8 +168,9 @@ func (m *Metrics) ActionDuration(sensorName, triggerName string, num float64) {
func (m *Metrics) Run(ctx context.Context, addr string) {
log := logging.FromContext(ctx)
metricsRegistry := prometheus.NewRegistry()
metricsRegistry.MustRegister(m)
metricsRegistry.MustRegister(collectors.NewGoCollector(), m)
http.Handle("/metrics", promhttp.HandlerFor(metricsRegistry, promhttp.HandlerOpts{}))

log.Info("starting metrics server")
if err := http.ListenAndServe(addr, nil); err != nil {
log.Fatalw("failed to start metrics server", zap.Error(err))
Expand Down

0 comments on commit 1c30347

Please sign in to comment.