Skip to content

Commit b924c0b

Browse files
added monthly requests limit to postman api request metrics collection (#4667)
1 parent f3eff52 commit b924c0b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/sources/postman/metrics.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
type metrics struct {
1010
apiRequests *prometheus.CounterVec
1111
apiMonthlyRequestsRemaining *prometheus.GaugeVec
12+
apiMonthlyRequestsLimit *prometheus.GaugeVec
1213
}
1314

1415
var (
@@ -27,6 +28,14 @@ var (
2728
Help: "Total number of Postman API requests remaining this month.",
2829
},
2930
[]string{"source_name"})
31+
32+
postmanAPIMonthlyRequestsLimit = promauto.NewGaugeVec(prometheus.GaugeOpts{
33+
Namespace: common.MetricsNamespace,
34+
Subsystem: common.MetricsSubsystem,
35+
Name: "postman_api_monthly_requests_limit",
36+
Help: "Total monthly Postman API request limit.",
37+
},
38+
[]string{"source_name"})
3039
)
3140

3241
func newMetrics(sourceName string) *metrics {
@@ -37,5 +46,8 @@ func newMetrics(sourceName string) *metrics {
3746
apiMonthlyRequestsRemaining: postmanAPIMonthlyRequestsRemaining.MustCurryWith(map[string]string{
3847
"source_name": sourceName,
3948
}),
49+
apiMonthlyRequestsLimit: postmanAPIMonthlyRequestsLimit.MustCurryWith(map[string]string{
50+
"source_name": sourceName,
51+
}),
4052
}
4153
}

pkg/sources/postman/postman_client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ func (c *Client) handleRateLimits(ctx trContext.Context, resp *http.Response) er
345345
return nil
346346
}
347347

348+
c.Metrics.apiMonthlyRequestsLimit.WithLabelValues().Set(
349+
float64(rateLimitTotalMonth),
350+
)
351+
348352
if rateLimitTotalMonth == 0 {
349353
ctx.Logger().V(2).Info("RateLimit-Limit-Month is zero, cannot compute usage percentage")
350354
return nil

0 commit comments

Comments
 (0)