mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
Add prometheus metrics to measure hook execution time (#2312)
* Add prometheus metrics to measure hook execution time * Move metrics to separate file and reduce buckets
This commit is contained in:
parent
383f8a1f67
commit
2d96b89554
2 changed files with 21 additions and 0 deletions
|
@ -183,6 +183,10 @@ func (jp *JobProgress) TrackProgress(progress *Progress) {
|
|||
// executeHooks is a helper method to execute all the hooks for the given
|
||||
// closure.
|
||||
func (jp *JobProgress) executeHooks(todo func(hook JobProgressHook)) {
|
||||
defer func(start time.Time) {
|
||||
elapsed := time.Since(start).Milliseconds()
|
||||
hooksExecTime.WithLabelValues().Observe(float64(elapsed))
|
||||
}(time.Now())
|
||||
for _, hook := range jp.hooks {
|
||||
// TODO: Non-blocking?
|
||||
todo(hook)
|
||||
|
|
17
pkg/sources/metrics.go
Normal file
17
pkg/sources/metrics.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package sources
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
|
||||
)
|
||||
|
||||
var (
|
||||
hooksExecTime = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: common.MetricsNamespace,
|
||||
Subsystem: common.MetricsSubsystem,
|
||||
Name: "hooks_exec_time_ms",
|
||||
Help: "Time spent executing hooks (ms)",
|
||||
Buckets: []float64{5, 50, 500, 1000},
|
||||
}, nil)
|
||||
)
|
Loading…
Reference in a new issue