Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions internal/collector/nginxplusreceiver/record/cache_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) F5, Inc.
//
// This source code is licensed under the Apache License, Version 2.0 license found in the
// LICENSE file in the root directory of this source tree.

package record

import (
"github.com/nginx/agent/v3/internal/collector/nginxplusreceiver/internal/metadata"
plusapi "github.com/nginxinc/nginx-plus-go-client/v2/client"
"go.opentelemetry.io/collector/pdata/pcommon"
)

func RecordCacheMetrics(mb *metadata.MetricsBuilder, stats *plusapi.Stats, now pcommon.Timestamp) {
for name, cache := range stats.Caches {
// Cache Bytes
mb.RecordNginxCacheBytesReadDataPoint(
now,
int64(cache.Bypass.Bytes),
metadata.AttributeNginxCacheOutcomeBYPASS,
name,
)
mb.RecordNginxCacheBytesReadDataPoint(
now,
int64(cache.Expired.Bytes),
metadata.AttributeNginxCacheOutcomeEXPIRED,
name,
)
mb.RecordNginxCacheBytesReadDataPoint(
now,
int64(cache.Hit.Bytes),
metadata.AttributeNginxCacheOutcomeHIT,
name,
)
mb.RecordNginxCacheBytesReadDataPoint(
now,
int64(cache.Miss.Bytes),
metadata.AttributeNginxCacheOutcomeMISS,
name,
)
mb.RecordNginxCacheBytesReadDataPoint(
now,
int64(cache.Revalidated.Bytes),
metadata.AttributeNginxCacheOutcomeREVALIDATED,
name,
)
mb.RecordNginxCacheBytesReadDataPoint(
now,
int64(cache.Stale.Bytes),
metadata.AttributeNginxCacheOutcomeSTALE,
name,
)
mb.RecordNginxCacheBytesReadDataPoint(
now,
int64(cache.Updating.Bytes),
metadata.AttributeNginxCacheOutcomeUPDATING,
name,
)

// Cache Memory
mb.RecordNginxCacheMemoryLimitDataPoint(now, int64(cache.MaxSize), name)
mb.RecordNginxCacheMemoryUsageDataPoint(now, int64(cache.Size), name)

// Cache Responses
mb.RecordNginxCacheResponsesDataPoint(
now,
int64(cache.Bypass.Responses),
metadata.AttributeNginxCacheOutcomeBYPASS,
name,
)
mb.RecordNginxCacheResponsesDataPoint(
now,
int64(cache.Expired.Responses),
metadata.AttributeNginxCacheOutcomeEXPIRED,
name,
)
mb.RecordNginxCacheResponsesDataPoint(
now,
int64(cache.Hit.Responses),
metadata.AttributeNginxCacheOutcomeHIT,
name,
)
mb.RecordNginxCacheResponsesDataPoint(
now,
int64(cache.Miss.Responses),
metadata.AttributeNginxCacheOutcomeMISS,
name,
)
mb.RecordNginxCacheResponsesDataPoint(
now,
int64(cache.Revalidated.Responses),
metadata.AttributeNginxCacheOutcomeREVALIDATED,
name,
)
mb.RecordNginxCacheResponsesDataPoint(
now,
int64(cache.Stale.Responses),
metadata.AttributeNginxCacheOutcomeSTALE,
name,
)
mb.RecordNginxCacheResponsesDataPoint(
now,
int64(cache.Updating.Responses),
metadata.AttributeNginxCacheOutcomeUPDATING,
name,
)
}
}
114 changes: 114 additions & 0 deletions internal/collector/nginxplusreceiver/record/http_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright (c) F5, Inc.
//
// This source code is licensed under the Apache License, Version 2.0 license found in the
// LICENSE file in the root directory of this source tree.

package record

import (
"github.com/nginx/agent/v3/internal/collector/nginxplusreceiver/internal/metadata"
plusapi "github.com/nginxinc/nginx-plus-go-client/v2/client"
"go.opentelemetry.io/collector/pdata/pcommon"
)

type HTTPMetrics struct {
mb *metadata.MetricsBuilder
PreviousHTTPRequestsTotal uint64
}

func NewHTTPMetrics(stats *plusapi.Stats, mb *metadata.MetricsBuilder) *HTTPMetrics {
return &HTTPMetrics{
mb: mb,
PreviousHTTPRequestsTotal: stats.HTTPRequests.Total,
}
}

func (hm *HTTPMetrics) RecordHTTPMetrics(stats *plusapi.Stats, now pcommon.Timestamp) {
// Requests
hm.mb.RecordNginxHTTPRequestsDataPoint(now, int64(stats.HTTPRequests.Total), "", 0)

// Request Count
requestsDiff := int64(stats.HTTPRequests.Total) - int64(hm.PreviousHTTPRequestsTotal)
hm.mb.RecordNginxHTTPRequestCountDataPoint(now, requestsDiff, "", 0)
hm.PreviousHTTPRequestsTotal = stats.HTTPRequests.Total

// Connections
hm.mb.RecordNginxHTTPConnectionsDataPoint(
now,
int64(stats.Connections.Accepted),
metadata.AttributeNginxConnectionsOutcomeACCEPTED,
)
hm.mb.RecordNginxHTTPConnectionsDataPoint(
now,
int64(stats.Connections.Dropped),
metadata.AttributeNginxConnectionsOutcomeDROPPED,
)
hm.mb.RecordNginxHTTPConnectionCountDataPoint(
now,
int64(stats.Connections.Active),
metadata.AttributeNginxConnectionsOutcomeACTIVE,
)
hm.mb.RecordNginxHTTPConnectionCountDataPoint(
now,
int64(stats.Connections.Idle),
metadata.AttributeNginxConnectionsOutcomeIDLE,
)
}

func (hm *HTTPMetrics) RecordHTTPLimitMetrics(stats *plusapi.Stats, now pcommon.Timestamp) {
// Limit Connections
for name, limitConnection := range stats.HTTPLimitConnections {
hm.mb.RecordNginxHTTPLimitConnRequestsDataPoint(
now,
int64(limitConnection.Passed),
metadata.AttributeNginxLimitConnOutcomePASSED,
name,
)
hm.mb.RecordNginxHTTPLimitConnRequestsDataPoint(
now,
int64(limitConnection.Rejected),
metadata.AttributeNginxLimitConnOutcomeREJECTED,
name,
)
hm.mb.RecordNginxHTTPLimitConnRequestsDataPoint(
now,
int64(limitConnection.RejectedDryRun),
metadata.AttributeNginxLimitConnOutcomeREJECTEDDRYRUN,
name,
)
}

// Limit Requests
for name, limitRequest := range stats.HTTPLimitRequests {
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
now,
int64(limitRequest.Passed),
metadata.AttributeNginxLimitReqOutcomePASSED,
name,
)
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
now,
int64(limitRequest.Rejected),
metadata.AttributeNginxLimitReqOutcomeREJECTED,
name,
)
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
now,
int64(limitRequest.RejectedDryRun),
metadata.AttributeNginxLimitReqOutcomeREJECTEDDRYRUN,
name,
)
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
now,
int64(limitRequest.Delayed),
metadata.AttributeNginxLimitReqOutcomeDELAYED,
name,
)
hm.mb.RecordNginxHTTPLimitReqRequestsDataPoint(
now,
int64(limitRequest.DelayedDryRun),
metadata.AttributeNginxLimitReqOutcomeDELAYEDDRYRUN,
name,
)
}
}
Loading
Loading