Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 55 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Exporter struct {
locustUp,
locustUsers,
locustFailRatio,
locustCurrentResponseTimePercentileNinetyFifth,
locustCurrentResponseTimePercentileNinetyFifth prometheus.Gauge
locustCurrentResponseTimePercentileFiftieth prometheus.Gauge
locustRunning,
locustWorkersCount,
Expand All @@ -51,7 +51,9 @@ type Exporter struct {
locustMedianResponseTime,
locustAvgContentLength,
locustErrors *prometheus.GaugeVec
totalScrapes prometheus.Counter
locustResponseTimePercentile99 prometheus.GaugeVec
locustResponseTimePercentile95 prometheus.GaugeVec
totalScrapes prometheus.Counter
}

// NewExporter function
Expand Down Expand Up @@ -238,6 +240,24 @@ func NewExporter(uri string, timeout time.Duration) (*Exporter, error) {
Help: "The total number of scrapes.",
},
),
locustResponseTimePercentile95: *prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "requests",
Name: "response_time_percentile_95",
Help: "The 95th percentile of response time per endpoint.",
},
[]string{"method", "name"},
),
locustResponseTimePercentile99: *prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "requests",
Name: "response_time_percentile_99",
Help: "The 99th percentile of response time per endpoint.",
},
[]string{"method", "name"},
),
}, nil
}

Expand Down Expand Up @@ -267,6 +287,8 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
e.locustMedianResponseTime.Describe(ch)
e.locustCurrentRps.Describe(ch)
e.locustAvgContentLength.Describe(ch)
e.locustResponseTimePercentile99.Describe(ch)
e.locustResponseTimePercentile95.Describe(ch)
e.locustErrors.Describe(ch)
e.locustWorkersDetail.Describe(ch)
}
Expand All @@ -287,38 +309,46 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
e.locustCurrentRps.Collect(ch)
e.locustMedianResponseTime.Collect(ch)
e.locustAvgContentLength.Collect(ch)
e.locustResponseTimePercentile99.Collect(ch)
e.locustResponseTimePercentile95.Collect(ch)
e.locustErrors.Collect(ch)
e.locustWorkersDetail.Collect(ch)
}

type locustStats struct {
Stats []struct {
Method string `json:"method"`
Name string `json:"name"`
NumRequests int `json:"num_requests"`
NumFailures int `json:"num_failures"`
AvgResponseTime float64 `json:"avg_response_time"`
CurrentFailPerSec float64 `json:"current_fail_per_sec"`
MinResponseTime float64 `json:"min_response_time"`
MaxResponseTime float64 `json:"max_response_time"`
CurrentRps float64 `json:"current_rps"`
MedianResponseTime float64 `json:"median_response_time"`
AvgContentLength float64 `json:"avg_content_length"`
Method string `json:"method"`
Name string `json:"name"`
NumRequests int `json:"num_requests"`
NumFailures int `json:"num_failures"`
AvgResponseTime float64 `json:"avg_response_time"`
CurrentFailPerSec float64 `json:"current_fail_per_sec"`
MinResponseTime float64 `json:"min_response_time"`
MaxResponseTime float64 `json:"max_response_time"`
CurrentRps float64 `json:"current_rps"`
MedianResponseTime float64 `json:"median_response_time"`
AvgContentLength float64 `json:"avg_content_length"`
ResponseTimePercentile99 float64 `json:"response_time_percentile_0.99"`
ResponseTimePercentile95 float64 `json:"response_time_percentile_0.95"`
} `json:"stats"`
Errors []struct {
Method string `json:"method"`
Name string `json:"name"`
Error string `json:"error"`
Occurrences int `json:"occurrences"`
} `json:"errors"`
TotalRps float64 `json:"total_rps"`
FailRatio float64 `json:"fail_ratio"`
CurrentResponseTimePercentileNinetyFifth float64 `json:"current_response_time_percentile_95"`
CurrentResponseTimePercentileFiftieth float64 `json:"current_response_time_percentile_50"`
WorkerCount int `json:"worker_count,omitempty"`
State string `json:"state"`
UserCount int `json:"user_count"`
Workers []struct {
CurrentResponseTimePercentiles struct {
CurrentResponseTimePercentileNinetyFifth float64 `json:"response_time_percentile_0.95"`
CurrentResponseTimePercentileFiftieth float64 `json:"response_time_percentile_0.5"`
} `json:"current_response_time_percentiles"`
TotalRps float64 `json:"total_rps"`
FailRatio float64 `json:"fail_ratio"`
//CurrentResponseTimePercentileNinetyFifth float64 `json:"response_time_percentile_0.95"`
//CurrentResponseTimePercentileFiftieth float64 `json:"response_time_percentile_0.5"`
WorkerCount int `json:"worker_count,omitempty"`
State string `json:"state"`
UserCount int `json:"user_count"`
Workers []struct {
Id string `json:"id"`
State string `json:"state"`
UserCount int `json:"user_count"`
Expand Down Expand Up @@ -346,8 +376,8 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) (up float64) {

ch <- prometheus.MustNewConstMetric(e.locustUsers.Desc(), prometheus.GaugeValue, float64(locustStats.UserCount))
ch <- prometheus.MustNewConstMetric(e.locustFailRatio.Desc(), prometheus.GaugeValue, float64(locustStats.FailRatio))
ch <- prometheus.MustNewConstMetric(e.locustCurrentResponseTimePercentileNinetyFifth.Desc(), prometheus.GaugeValue, float64(locustStats.CurrentResponseTimePercentileNinetyFifth))
ch <- prometheus.MustNewConstMetric(e.locustCurrentResponseTimePercentileFiftieth.Desc(), prometheus.GaugeValue, float64(locustStats.CurrentResponseTimePercentileFiftieth))
ch <- prometheus.MustNewConstMetric(e.locustCurrentResponseTimePercentileNinetyFifth.Desc(), prometheus.GaugeValue, locustStats.CurrentResponseTimePercentiles.CurrentResponseTimePercentileNinetyFifth)
ch <- prometheus.MustNewConstMetric(e.locustCurrentResponseTimePercentileFiftieth.Desc(), prometheus.GaugeValue, locustStats.CurrentResponseTimePercentiles.CurrentResponseTimePercentileFiftieth)
ch <- prometheus.MustNewConstMetric(e.locustWorkersCount.Desc(), prometheus.GaugeValue, float64(len(locustStats.Workers)))
ch <- prometheus.MustNewConstMetric(e.locustWorkersRunningCount.Desc(), prometheus.GaugeValue, countWorkersByState(locustStats, "running"))
ch <- prometheus.MustNewConstMetric(e.locustWorkersHatchingCount.Desc(), prometheus.GaugeValue, countWorkersByState(locustStats, "hatching"))
Expand All @@ -364,6 +394,8 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) (up float64) {
e.locustCurrentRps.WithLabelValues(r.Method, r.Name).Set(r.CurrentRps)
e.locustMedianResponseTime.WithLabelValues(r.Method, r.Name).Set(r.MedianResponseTime)
e.locustAvgContentLength.WithLabelValues(r.Method, r.Name).Set(r.AvgContentLength)
e.locustResponseTimePercentile99.WithLabelValues(r.Method, r.Name).Set(r.ResponseTimePercentile99)
e.locustResponseTimePercentile95.WithLabelValues(r.Method, r.Name).Set(r.ResponseTimePercentile95)
}
}

Expand Down