added monthly requests limit to postman api request metrics collection (#4667)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
type metrics struct {
|
||||
apiRequests *prometheus.CounterVec
|
||||
apiMonthlyRequestsRemaining *prometheus.GaugeVec
|
||||
apiMonthlyRequestsLimit *prometheus.GaugeVec
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -27,6 +28,14 @@ var (
|
||||
Help: "Total number of Postman API requests remaining this month.",
|
||||
},
|
||||
[]string{"source_name"})
|
||||
|
||||
postmanAPIMonthlyRequestsLimit = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: common.MetricsNamespace,
|
||||
Subsystem: common.MetricsSubsystem,
|
||||
Name: "postman_api_monthly_requests_limit",
|
||||
Help: "Total monthly Postman API request limit.",
|
||||
},
|
||||
[]string{"source_name"})
|
||||
)
|
||||
|
||||
func newMetrics(sourceName string) *metrics {
|
||||
@@ -37,5 +46,8 @@ func newMetrics(sourceName string) *metrics {
|
||||
apiMonthlyRequestsRemaining: postmanAPIMonthlyRequestsRemaining.MustCurryWith(map[string]string{
|
||||
"source_name": sourceName,
|
||||
}),
|
||||
apiMonthlyRequestsLimit: postmanAPIMonthlyRequestsLimit.MustCurryWith(map[string]string{
|
||||
"source_name": sourceName,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,6 +345,10 @@ func (c *Client) handleRateLimits(ctx trContext.Context, resp *http.Response) er
|
||||
return nil
|
||||
}
|
||||
|
||||
c.Metrics.apiMonthlyRequestsLimit.WithLabelValues().Set(
|
||||
float64(rateLimitTotalMonth),
|
||||
)
|
||||
|
||||
if rateLimitTotalMonth == 0 {
|
||||
ctx.Logger().V(2).Info("RateLimit-Limit-Month is zero, cannot compute usage percentage")
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user