Skip to content

Commit

Permalink
add init duration to prometheus metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Mason <mason@packet.com>
  • Loading branch information
mikemrm committed Aug 20, 2020
1 parent 80d8895 commit 8cc4f4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/packethost/hegel/grpc/hegel"
"github.com/packethost/hegel/metrics"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
tink "github.com/tinkerbell/tink/protos/hardware"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/peer"
Expand Down Expand Up @@ -213,13 +214,15 @@ func (s *server) Subscribe(in *hegel.SubscribeRequest, stream hegel.Hegel_Subscr
startedAt := time.Now().UTC()
metrics.TotalSubscriptions.Inc()
metrics.Subscriptions.WithLabelValues("initializing").Inc()
timer := prometheus.NewTimer(metrics.InitDuration)

logger := s.log.With("op", "subscribe")

initError := func(err error) error {
logger.Error(err)
metrics.Subscriptions.WithLabelValues("initializing").Dec()
metrics.Errors.WithLabelValues("subscribe", "initializing").Inc()
timer.ObserveDuration()
return err
}

Expand Down Expand Up @@ -317,6 +320,7 @@ func (s *server) Subscribe(in *hegel.SubscribeRequest, stream hegel.Hegel_Subscr
}
}()

timer.ObserveDuration()
metrics.Subscriptions.WithLabelValues("initializing").Dec()
metrics.Subscriptions.WithLabelValues("active").Inc()

Expand Down
7 changes: 7 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
var (
CacherConnected prometheus.Gauge
CacherHealthcheck *prometheus.CounterVec
InitDuration prometheus.Observer
Errors *prometheus.CounterVec
MetadataRequests prometheus.Counter
State prometheus.Gauge
Expand All @@ -39,6 +40,12 @@ func Init(_ log.Logger) {
}
initCounterLabels(CacherHealthcheck, labelValues)

InitDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "hegel_subscription_initialization_duration_seconds",
Help: "Duration taken to get a responce for a newly discovered request.",
Buckets: []float64{0.5, 1, 5, 10, 30, 60},
}, []string{}).With(prometheus.Labels{})

Errors = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "hegel_errors",
Help: "Number of errors tracked by hegel",
Expand Down

0 comments on commit 8cc4f4a

Please sign in to comment.