added monthly requests limit to postman api request metrics collection (#4667)

This commit is contained in:
Shahzad Haider
2026-01-15 23:33:49 +05:00
committed by GitHub
parent f3eff52825
commit b924c0bfbe
2 changed files with 16 additions and 0 deletions
+12
View File
@@ -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,
}),
}
}
+4
View File
@@ -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