8000 Refactor Plus Scraper (#1264) · nginx/agent@d64abd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit d64abd2

Browse files
authored
Refactor Plus Scraper (#1264)
1 parent 6b064a4 commit d64abd2

File tree

10 files changed

+1309
-1127
lines changed

10 files changed

+1309
-1127
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) F5, Inc.
2+
//
3+
// This source code is licensed under the Apache License, Version 2.0 license found in the
4+
// LICENSE file in the root directory of this source tree.
5+
6+
package record
7+
8+
import (
9+
"github.com/nginx/agent/v3/internal/collector/nginxplusreceiver/internal/metadata"
10+
plusapi "github.com/nginxinc/nginx-plus-go-client/v2/client"
11+
"go.opentelemetry.io/collector/pdata/pcommon"
12+
)
13+
14+
func RecordCacheMetrics(mb *metadata.MetricsBuilder, stats *plusapi.Stats, now pcommon.Timestamp) {
15+
for name, cache := range stats.Caches {
16+
// Cache Bytes
17+
mb.RecordNginxCacheBytesReadDataPoint(
18+
now,
19+
int64(cache.Bypass.Bytes),
20+
metadata.AttributeNginxCacheOutcomeBYPASS,
21+
name,
22+
)
23+
mb.RecordNginxCacheBytesReadDataPoint(
24+
now,
25+
int64(cache.Expired.Bytes),
26+
metadata.AttributeNginxCacheOutcomeEXPIRED,
27+
name,
28+
)
29+
mb.RecordNginxCacheBytesReadDataPoint(
30+
now,
31+
int64(cache.Hit.Bytes),
32+
metadata.AttributeNginxCacheOutcomeHIT,
33+
name,
34+
)
35+
mb.RecordNginxCacheBytesReadDataPoint(
36+
now,
37+
int64(cache.Miss.Bytes),
38+
metadata.AttributeNginxCacheOutcomeMISS,
39 10BC0 +
name,
40+
)
41+
mb.RecordNginxCacheBytesReadDataPoint(
42+
now,
43+
int64(cache.Revalidated.Bytes),
44+
metadata.AttributeNginxCacheOutcomeREVALIDATED,
45+
name,
46+
)
47+
mb.RecordNginxCacheBytesReadDataPoint(
48+
now,
49+
int64(cache.Stale.Bytes),
50+
metadata.AttributeNginxCacheOutcomeSTALE,
51+
name,
52+
)
53+
mb.RecordNginxCacheBytesReadDataPoint(
54+
now,
55+
int64(cache.Updating.Bytes),
56+
metadata.AttributeNginxCacheOutcomeUPDATING,
57+
name,
58+
)
59+
60+
// Cache Memory
61+
mb.RecordNginxCacheMemoryLimitDataPoint(now, int64(cache.MaxSize), name)
62+
mb.RecordNginxCacheMemoryUsageDataPoint(now, int64(cache.Size), name)
63+
64+
// Cache Responses
65+
mb.RecordNginxCacheResponsesDataPoint(
66+
now,
67+
int64(cache.Bypass.Responses),
68+
metadata.AttributeNginxCacheOutcomeBYPASS,
69+
name,
70+
)
71+
mb.RecordNginxCacheResponsesDataPoint(
72+
now,
73+
int64(cache.Expired.Responses),
74+
metadata.AttributeNginxCacheOutcomeEXPIRED,
75+
name,
76+
)
77+
mb.RecordNginxCacheResponsesDataPoint(
78+
now,
79+
int64(cache.Hit.Responses),
80+
metadata.AttributeNginxCacheOutcomeHIT,
81+
name,
82+
)
83+
mb.RecordNginxCacheResponsesDataPoint(
84+
now,
85+
int64(cache.Miss.Responses),
86+
metadata.AttributeNginxCacheOutcomeMISS,
87+
name,
88+
)
89+
mb.RecordNginxCacheResponsesDataPoint(
90+
now,
91+
int64(cache.Revalidated.Responses),
92+
metadata.AttributeNginxCacheOutcomeREVALIDATED,
93+
name,
94+
)
95+
mb.RecordNginxCacheResponsesDataPoint(
96+
now,
97+
int64(cache.Stale.Responses),
98+
metadata.AttributeNginxCacheOutcomeSTALE,
99+
name,
100+
)
101+
mb.RecordNginxCacheResponsesDataPoint(
102+
now,
103+
int64(cache.Updating.Responses),
104+
metadata.AttributeNginxCacheOutcomeUPDATING,
105+
name,
106+
)
107+
}
108+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) F5, Inc.
2+
//
3+
// This source code is licensed under the Apache License, Version 2.0 license found in the
4+
// LICENSE file in the root directory of this source tree.
5+
6+
package record
7+
8+
import (
9+
"github.com/nginx/agent/v3/internal/collector/nginxplusreceiver/internal/metadata"
10+
plusapi "github.com/nginxinc/nginx-plus-go-client/v2/client"
11+
"go.opentelemetry.io/collector/pdata/pcommon"
12+
)
13+
14+
type HTTPMetrics struct {
15+
mb *metadata.MetricsBuilder
16+
PreviousHTTPRequestsTotal uint64
17+
}
18+
19+
func NewHTTPMetrics(stats *plusapi.Stats, mb *metadata.MetricsBuilder) *HTTPMetrics {
20+
return &HTTPMetrics{
21+
mb: mb,
22+
PreviousHTTPRequestsTotal: stats.HTTPRequests.Total,
23+
}
24+
}
25+
26+
func (hm *HTTPMetrics) RecordHTTPMetrics(stats *plusapi.Stats, now pcommon.Timestamp) {
27+
// Requests
28+
hm.mb.RecordNginxHTTPRequestsDataPoint(now, int64(stats.HTTPRequests.Total), "", 0)
29+
30+
// Request Count
31+
requestsDiff := int64(stats.HTTPRequests.Total) - int64(hm.PreviousHTTPRequestsTotal)
32+
hm.mb.RecordNginxHTTPRequestCountDataPoint(now, requestsDiff, "", 0)
33+
hm.PreviousHTTPRequestsTotal = stats.HTTPRequests.Total
34+
35+
// Connections
36+
hm.mb.RecordNginxHTTPConnectionsDataPoint(
37+
now,
38+
int64(stats.Connections.Accepted),
39+
metadata.AttributeNginxConnectionsOutcomeACCEPTED,
40+
)
41+
hm.mb.RecordNginxHTTPConnectionsDataPoint(
42+
now,
43+
int64(stats.Connections.Dropped),
44+
metadata.AttributeNginxConnectionsOutcomeDROPPED,
45+
)
46+
hm.mb.RecordNginxHTTPConnectionCountDataPoint(
47+
now,
48+
int64(stats.Connections.Active),
49+
metadata.AttributeNginxConnectionsOutcomeACTIVE,
50+
)
51+
hm.mb.RecordNginxHTTPConnectionCountDataPoint(
52+
now,
53+
int64(stats.Connections.Idle),
54+
metadata.AttributeNginxConnectionsOutcomeIDLE,
55+
)
56+
}
57+
58+
func (hm *HTTPMetrics) RecordHTTPLimitMetrics(stats *plusapi.Stats, now pcommon.Timestamp) {
59+
// Limit Connections
60+
for name, limitConnection := range stats.HTTPLimitConnections {
61+
hm.mb.RecordNginxHTTPLimitConnRequestsDataPoint(
62+
now,
63+
int64(limitConnection.Passed),
64+
metadata.AttributeNginxLimitConnOutcomePASSED,
65+
name,
66+
)
67+
hm.mb.RecordNginxHTTPLimitConnRequestsDataPoint(
68+
now,
69+
int64(limitConnection.Rejected),
70+
metadata.AttributeNginxLimitConnOutcomeREJECTED,
71+
name,
72+
)
73+
hm.mb.RecordNginxHTTPLimitConnRequestsDataPoint(
74+
now,
75+
int64(limitConnection.RejectedDryRun),
76+
metadata.AttributeNginxLimitConnOutcomeREJECTEDDRYRUN,
77+
name,
78+
)
79+
}
80+
81+
// Limit Requests
82+
for name, limitRequest := range stats.HTTPLimitRequests {
83+
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
84+
now,
85+
int64(limitRequest.Passed),
86+
metadata.AttributeNginxLimitReqOutcomePASSED,
87+
name,
88+
)
89+
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
90+
now,
91+
int64(limitRequest.Rejected),
92+
metadata.AttributeNginxLimitReqOutcomeREJECTED,
93+
name,
94+
)
95+
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
96+
now,
97+
int64(limitRequest.RejectedDryRun),
98+
metadata.AttributeNginxLimitReqOutcomeREJECTEDDRYRUN,
99+
name,
100+
)
101+
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
102+
now,
103+
int64(limitRequest.Delayed),
104+
metadata.AttributeNginxLimitReqOutcomeDELAYED,
105+
name,
106+
)
107+
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
108+
now,
109+
int64(limitRequest.DelayedDryRun),
110+
metadata.AttributeNginxLimitReqOutcomeDELAYEDDRYRUN,
111+
name,
112+
)
113+
}
114+
}

0 commit comments

Comments
 (0)
0