fix: report metrics to prometheus

This commit is contained in:
徐聪
2022-07-21 18:01:27 +08:00
parent 6a812c6374
commit 4784d16639
4 changed files with 12 additions and 32 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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 (