|
| 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