Skip to content

Commit 0f3c711

Browse files
authored
Fix request count metric for NGINX Plus receiver (#1096)
1 parent cfb3d58 commit 0f3c711

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

internal/collector/nginxplusreceiver/scraper.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type NginxPlusScraper struct {
4646
logger *zap.Logger
4747
settings receiver.Settings
4848
init sync.Once
49+
previousHTTPRequestsTotal uint64
4950
}
5051

5152
type ResponseStatuses struct {
@@ -107,6 +108,8 @@ func (nps *NginxPlusScraper) Scrape(ctx context.Context) (pmetric.Metrics, error
107108
nps.logger.Error("Failed to get stats from plus API", zap.Error(err))
108109
return
109110
}
111+
112+
nps.previousHTTPRequestsTotal = stats.HTTPRequests.Total
110113
nps.createPreviousServerZoneResponses(stats)
111114
nps.createPreviousLocationZoneResponses(stats)
112115
})
@@ -194,7 +197,10 @@ func (nps *NginxPlusScraper) recordMetrics(stats *plusapi.Stats) {
194197

195198
// HTTP Requests
196199
nps.mb.RecordNginxHTTPRequestsDataPoint(now, int64(stats.HTTPRequests.Total), "", 0)
197-
nps.mb.RecordNginxHTTPRequestCountDataPoint(now, int64(stats.HTTPRequests.Current))
200+
201+
requestsDiff := int64(stats.HTTPRequests.Total) - int64(nps.previousHTTPRequestsTotal)
202+
nps.mb.RecordNginxHTTPRequestCountDataPoint(now, requestsDiff)
203+
nps.previousHTTPRequestsTotal = stats.HTTPRequests.Total
198204

199205
nps.recordCacheMetrics(stats, now)
200206
nps.recordHTTPLimitMetrics(stats, now)

internal/collector/nginxplusreceiver/scraper_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ func TestScraper(t *testing.T) {
5858
},
5959
}
6060

61+
scraper.previousHTTPRequestsTotal = 3
62+
6163
actualMetrics, err := scraper.Scrape(context.Background())
6264
require.NoError(t, err)
6365

internal/collector/nginxplusreceiver/testdata/expected.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ resourceMetrics:
295295
gauge:
296296
aggregationTemporality: 2
297297
dataPoints:
298-
- asInt: "3"
298+
- asInt: "44"
299299
timeUnixNano: "1000000"
300300
isMonotonic: true
301301
unit: requests

0 commit comments

Comments
 (0)