Skip to content
Snippets Groups Projects
prometheus.go 840 B
Newer Older
  • Learn to ignore specific revisions
  • package metrics
    
    import (
    	"time"
    
    	"github.com/prometheus/client_golang/prometheus"
    )
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    // nolint
    // TODO: add description
    
    func StartHook(labels prometheus.Labels, counter *prometheus.CounterVec) time.Time {
    	counter.With(labels).Inc()
    	return time.Now()
    }
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    // nolint
    // TODO: add description
    
    func FinishHook(labels prometheus.Labels, start time.Time, counter *prometheus.CounterVec, hist *prometheus.HistogramVec) {
    	duration := time.Since(start)
    	counter.With(labels).Add(duration.Seconds())
    	hist.With(labels).Observe(duration.Seconds())
    }
    
    
    Malte Bauch's avatar
    Malte Bauch committed
    // nolint
    // TODO: add description
    
    func HandleError(labels prometheus.Labels, err error, counter *prometheus.CounterVec) error {
    	errLabels := make(prometheus.Labels)
    	for k, v := range labels {
    		errLabels[k] = v
    	}
    	errLabels["error"] = err.Error()
    	counter.With(errLabels).Inc()
    	return err
    }