Expose number of failed hook executions
This commit is contained in:
parent
7eb95254a5
commit
3b745ad85d
|
@ -37,6 +37,14 @@ func (store hookDataStore) NewUpload(info tusd.FileInfo) (id string, err error)
|
|||
return store.DataStore.NewUpload(info)
|
||||
}
|
||||
|
||||
func SetupHookMetrics() {
|
||||
MetricsHookErrorsTotal.WithLabelValues(string(HookPostFinish)).Add(0)
|
||||
MetricsHookErrorsTotal.WithLabelValues(string(HookPostTerminate)).Add(0)
|
||||
MetricsHookErrorsTotal.WithLabelValues(string(HookPostReceive)).Add(0)
|
||||
MetricsHookErrorsTotal.WithLabelValues(string(HookPostCreate)).Add(0)
|
||||
MetricsHookErrorsTotal.WithLabelValues(string(HookPreCreate)).Add(0)
|
||||
}
|
||||
|
||||
func SetupPreHooks(composer *tusd.StoreComposer) {
|
||||
composer.UseCore(hookDataStore{
|
||||
DataStore: composer.Core,
|
||||
|
@ -94,6 +102,7 @@ func invokeHookSync(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byt
|
|||
|
||||
if err != nil {
|
||||
logEv(stderr, "HookInvocationError", "type", string(typ), "id", info.ID, "error", err.Error())
|
||||
MetricsHookErrorsTotal.WithLabelValues(string(typ)).Add(1)
|
||||
} else {
|
||||
logEv(stdout, "HookInvocationFinish", "type", string(typ), "id", info.ID)
|
||||
}
|
||||
|
|
|
@ -14,8 +14,17 @@ var MetricsOpenConnections = prometheus.NewGauge(prometheus.GaugeOpts{
|
|||
Help: "Current number of open connections.",
|
||||
})
|
||||
|
||||
var MetricsHookErrorsTotal = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "tusd_hook_errors_total",
|
||||
Help: "Total number of execution errors per hook type.",
|
||||
},
|
||||
[]string{"hooktype"},
|
||||
)
|
||||
|
||||
func SetupMetrics(handler *tusd.Handler) {
|
||||
prometheus.MustRegister(MetricsOpenConnections)
|
||||
prometheus.MustRegister(MetricsHookErrorsTotal)
|
||||
prometheus.MustRegister(prometheuscollector.New(handler.Metrics))
|
||||
|
||||
stdout.Printf("Using %s as the metrics path.\n", Flags.MetricsPath)
|
||||
|
|
|
@ -34,6 +34,7 @@ func Serve() {
|
|||
|
||||
if Flags.ExposeMetrics {
|
||||
SetupMetrics(handler)
|
||||
SetupHookMetrics()
|
||||
}
|
||||
|
||||
stdout.Printf(Composer.Capabilities())
|
||||
|
|
Loading…
Reference in New Issue