mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-30 12:59:39 +08:00
fix: report metrics to prometheus
This commit is contained in:
@@ -475,7 +475,8 @@ type PrometheusPusherOutput struct {
|
||||
|
||||
// OnStart will register all prometheus metric collectors
|
||||
func (o *PrometheusPusherOutput) OnStart() {
|
||||
o.reset()
|
||||
// reset all prometheus metrics
|
||||
resetPrometheusMetrics()
|
||||
log.Info().Msg("register prometheus metric collectors")
|
||||
registry := prometheus.NewRegistry()
|
||||
registry.MustRegister(
|
||||
@@ -608,9 +609,9 @@ func (o *PrometheusPusherOutput) OnEvent(data map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// reset will reset all metrics
|
||||
func (o *PrometheusPusherOutput) reset() {
|
||||
log.Info().Msg("reset metrics")
|
||||
// resetPrometheusMetrics will reset all metrics
|
||||
func resetPrometheusMetrics() {
|
||||
log.Info().Msg("reset all prometheus metrics")
|
||||
gaugeNumRequests.Reset()
|
||||
gaugeNumFailures.Reset()
|
||||
gaugeMedianResponseTime.Reset()
|
||||
|
||||
@@ -927,14 +927,15 @@ func (r *workerRunner) start() {
|
||||
|
||||
close(r.doneChan)
|
||||
|
||||
// notify master that worker is stopped
|
||||
r.onStopped()
|
||||
// wait until all stats are reported successfully
|
||||
<-r.reportedChan
|
||||
// report test result
|
||||
r.reportTestResult()
|
||||
// output teardown
|
||||
r.outputOnStop()
|
||||
|
||||
// notify master that worker is stopped
|
||||
r.onStopped()
|
||||
}()
|
||||
|
||||
// start stats report
|
||||
|
||||
@@ -8,10 +8,9 @@ import (
|
||||
|
||||
"github.com/httprunner/funplugin"
|
||||
"github.com/httprunner/funplugin/fungo"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user