Skip to content
7 changes: 7 additions & 0 deletions internal/collector/nginxplusreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ The total number of client requests received, since the last collection interval
| ---- | ----------- | ---------- |
| requests | Gauge | Int |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| nginx.zone.name | The name of the shared memory zone. | Any Str |
| nginx.zone.type | The type of shared memory zone, depending on what block it was defined in the NGINX configuration. | Str: ``SERVER``, ``LOCATION`` |

### nginx.http.request.discarded

The total number of requests completed without sending a response.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/collector/nginxplusreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ metrics:
gauge:
value_type: int
unit: "requests"
attributes:
- nginx.zone.name
- nginx.zone.type
nginx.cache.bytes_read:
enabled: true
description: The total number of bytes read from the cache or proxied server.
Expand Down
37 changes: 36 additions & 1 deletion internal/collector/nginxplusreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const (
type NginxPlusScraper struct {
previousServerZoneResponses map[string]ResponseStatuses
previousLocationZoneResponses map[string]ResponseStatuses
previousServerZoneRequests map[string]int64
previousLocationZoneRequests map[string]int64
plusClient *plusapi.NginxClient
cfg *Config
mb *metadata.MetricsBuilder
Expand Down Expand Up @@ -137,6 +139,8 @@ func (nps *NginxPlusScraper) Scrape(ctx context.Context) (pmetric.Metrics, error
nps.previousHTTPRequestsTotal = stats.HTTPRequests.Total
nps.createPreviousServerZoneResponses(stats)
nps.createPreviousLocationZoneResponses(stats)
nps.createPreviousServerZoneRequests(stats)
nps.createPreviousLocationZoneRequests(stats)
})

stats, err := nps.plusClient.GetStats(ctx)
Expand Down Expand Up @@ -175,6 +179,22 @@ func (nps *NginxPlusScraper) createPreviousLocationZoneResponses(stats *plusapi.
nps.previousLocationZoneResponses = previousLocationZoneResponses
}

func (nps *NginxPlusScraper) createPreviousServerZoneRequests(stats *plusapi.Stats) {
previousServerZoneRequests := make(map[string]int64)
for szName, sz := range stats.ServerZones {
previousServerZoneRequests[szName] = int64(sz.Requests)
}
nps.previousServerZoneRequests = previousServerZoneRequests
}

func (nps *NginxPlusScraper) createPreviousLocationZoneRequests(stats *plusapi.Stats) {
previousLocationZoneRequests := make(map[string]int64)
for lzName, lz := range stats.LocationZones {
previousLocationZoneRequests[lzName] = lz.Requests
}
nps.previousLocationZoneRequests = previousLocationZoneRequests
}

func (nps *NginxPlusScraper) createPreviousServerZoneResponses(stats *plusapi.Stats) {
previousServerZoneResponses := make(map[string]ResponseStatuses)
for szName, sz := range stats.ServerZones {
Expand Down Expand Up @@ -224,7 +244,7 @@ func (nps *NginxPlusScraper) recordMetrics(stats *plusapi.Stats) {
nps.mb.RecordNginxHTTPRequestsDataPoint(now, int64(stats.HTTPRequests.Total), "", 0)

requestsDiff := int64(stats.HTTPRequests.Total) - int64(nps.previousHTTPRequestsTotal)
nps.mb.RecordNginxHTTPRequestCountDataPoint(now, requestsDiff)
nps.mb.RecordNginxHTTPRequestCountDataPoint(now, requestsDiff, "", 0)
nps.previousHTTPRequestsTotal = stats.HTTPRequests.Total

nps.recordCacheMetrics(stats, now)
Expand Down Expand Up @@ -866,6 +886,13 @@ func (nps *NginxPlusScraper) recordServerZoneMetrics(stats *plusapi.Stats, now p

nps.mb.RecordNginxHTTPRequestsDataPoint(now, int64(sz.Requests), szName, metadata.AttributeNginxZoneTypeSERVER)

nps.mb.RecordNginxHTTPRequestCountDataPoint(now,
int64(sz.Requests)-nps.previousServerZoneRequests[szName],
szName,
metadata.AttributeNginxZoneTypeSERVER,
)
nps.previousServerZoneRequests[szName] = int64(sz.Requests)

nps.recordServerZoneHTTPMetrics(sz, szName, now)

nps.mb.RecordNginxHTTPRequestDiscardedDataPoint(now, int64(sz.Discarded),
Expand Down Expand Up @@ -975,6 +1002,14 @@ func (nps *NginxPlusScraper) recordLocationZoneMetrics(stats *plusapi.Stats, now
metadata.AttributeNginxZoneTypeLOCATION,
)

nps.mb.RecordNginxHTTPRequestCountDataPoint(now,
lz.Requests-nps.previousLocationZoneRequests[lzName],
lzName,
metadata.AttributeNginxZoneTypeLOCATION,
)

nps.previousLocationZoneRequests[lzName] = lz.Requests

nps.recordLocationZoneHTTPMetrics(lz, lzName, now)

nps.mb.RecordNginxHTTPRequestDiscardedDataPoint(now, lz.Discarded,
Expand Down
8 changes: 8 additions & 0 deletions internal/collector/nginxplusreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ func TestScraper(t *testing.T) {
},
}

scraper.previousLocationZoneRequests = map[string]int64{
"location_test": 30, // 5
}

scraper.previousServerZoneRequests = map[string]int64{
"test": 29, // 3
}

scraper.previousHTTPRequestsTotal = 3

actualMetrics, err := scraper.Scrape(context.Background())
Expand Down
25 changes: 25 additions & 0 deletions internal/collector/nginxplusreceiver/testdata/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,31 @@ resourceMetrics:
dataPoints:
- asInt: "44"
timeUnixNano: "1000000"
attributes:
- key: nginx.zone.name
value:
stringValue: ""
- key: nginx.zone.type
value:
stringValue: ""
- asInt: "3"
attributes:
- key: nginx.zone.name
value:
stringValue: test
- key: nginx.zone.type
value:
stringValue: SERVER
timeUnixNano: "1000000"
- asInt: "4"
attributes:
- key: nginx.zone.name
value:
stringValue: location_test
- key: nginx.zone.type
value:
stringValue: LOCATION
timeUnixNano: "1000000"
isMonotonic: true
unit: requests
- description: The total number of bytes read from the cache or proxied server.
Expand Down
Loading
Loading