From c4e660e2ff0435829ce6a4d9b09ebf90e1a9493c Mon Sep 17 00:00:00 2001 From: naman47vyas Date: Thu, 14 Nov 2024 17:41:50 +0530 Subject: [PATCH] server config stats --- receiver/nginxreceiver/documentation.md | 120 ++++ receiver/nginxreceiver/go.mod | 1 - receiver/nginxreceiver/go.sum | 2 - .../internal/metadata/generated_config.go | 70 ++- .../metadata/generated_config_test.go | 92 +-- .../internal/metadata/generated_metrics.go | 584 ++++++++++++++++-- .../metadata/generated_metrics_test.go | 186 ++++++ .../internal/metadata/testdata/config.yaml | 32 + receiver/nginxreceiver/metadata.yaml | 104 +++- receiver/nginxreceiver/scraper.go | 46 +- receiver/nginxreceiver/vts_stats.go | 2 +- 11 files changed, 1120 insertions(+), 119 deletions(-) diff --git a/receiver/nginxreceiver/documentation.md b/receiver/nginxreceiver/documentation.md index d70a21f09a08..8ca02722b47b 100644 --- a/receiver/nginxreceiver/documentation.md +++ b/receiver/nginxreceiver/documentation.md @@ -180,6 +180,36 @@ Bytes sent by server zones | ---- | ----------- | ------ | | serverzone_name | The name of serverzone | Any Str | +### nginx.upstream.peers.backup + +Whether upstream server is a backup server + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| {state} | Gauge | Int | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| upstream_block_name | The name of the upstream block | Any Str | +| upstream_peer_address | The address f the upstream server | Any Str | + +### nginx.upstream.peers.health_checks.last_passed + +Boolean indicating if the last health check request was successful and passed tests. + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| {status} | Gauge | Int | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| upstream_block_name | The name of the upstream block | Any Str | +| upstream_peer_address | The address f the upstream server | Any Str | + ### nginx.upstream.peers.received Bytes received from upstream servers @@ -225,6 +255,81 @@ The average time to receive the last byte of data from this server. | upstream_block_name | The name of the upstream block | Any Str | | upstream_peer_address | The address f the upstream server | Any Str | +### nginx.upstream.peers.responses.1xx + +Number of responses from upstream with 1xx status codes + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| responses | Sum | Int | Cumulative | true | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| upstream_block_name | The name of the upstream block | Any Str | +| upstream_peer_address | The address f the upstream server | Any Str | + +### nginx.upstream.peers.responses.2xx + +Number of responses from upstream with 2xx status codes + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| responses | Sum | Int | Cumulative | true | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| upstream_block_name | The name of the upstream block | Any Str | +| upstream_peer_address | The address f the upstream server | Any Str | + +### nginx.upstream.peers.responses.3xx + +Number of responses from upstream with 3xx status codes + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| responses | Sum | Int | Cumulative | true | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| upstream_block_name | The name of the upstream block | Any Str | +| upstream_peer_address | The address f the upstream server | Any Str | + +### nginx.upstream.peers.responses.4xx + +Number of responses from upstream with 4xx status codes + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| responses | Sum | Int | Cumulative | true | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| upstream_block_name | The name of the upstream block | Any Str | +| upstream_peer_address | The address f the upstream server | Any Str | + +### nginx.upstream.peers.responses.5xx + +Number of responses from upstream with 5xx status codes + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | +| ---- | ----------- | ---------- | ----------------------- | --------- | +| responses | Sum | Int | Cumulative | true | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| upstream_block_name | The name of the upstream block | Any Str | +| upstream_peer_address | The address f the upstream server | Any Str | + ### nginx.upstream.peers.sent Bytes sent from upstream servers @@ -239,3 +344,18 @@ Bytes sent from upstream servers | ---- | ----------- | ------ | | upstream_block_name | The name of the upstream block | Any Str | | upstream_peer_address | The address f the upstream server | Any Str | + +### nginx.upstream.peers.weight + +Weight of upstream server + +| Unit | Metric Type | Value Type | +| ---- | ----------- | ---------- | +| weight | Gauge | Double | + +#### Attributes + +| Name | Description | Values | +| ---- | ----------- | ------ | +| upstream_block_name | The name of the upstream block | Any Str | +| upstream_peer_address | The address f the upstream server | Any Str | diff --git a/receiver/nginxreceiver/go.mod b/receiver/nginxreceiver/go.mod index 775050f168c7..6cfbd06055c9 100644 --- a/receiver/nginxreceiver/go.mod +++ b/receiver/nginxreceiver/go.mod @@ -4,7 +4,6 @@ go 1.21.0 require ( github.com/google/go-cmp v0.6.0 - github.com/nginxinc/nginx-prometheus-exporter v0.11.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.102.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.102.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.102.0 diff --git a/receiver/nginxreceiver/go.sum b/receiver/nginxreceiver/go.sum index 0530c2d45d55..ca55a2bde33c 100644 --- a/receiver/nginxreceiver/go.sum +++ b/receiver/nginxreceiver/go.sum @@ -107,8 +107,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= -github.com/nginxinc/nginx-prometheus-exporter v0.11.0 h1:21xjnqNgxtni2jDgAQ90bl15uDnrTreO9sIlu1YsX/U= -github.com/nginxinc/nginx-prometheus-exporter v0.11.0/go.mod h1:GdyHnWAb8q8OW1Pssrrqbcqra0SH0Vn6UXICMmyWkw8= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= diff --git a/receiver/nginxreceiver/internal/metadata/generated_config.go b/receiver/nginxreceiver/internal/metadata/generated_config.go index a297a4130c21..d9df76607844 100644 --- a/receiver/nginxreceiver/internal/metadata/generated_config.go +++ b/receiver/nginxreceiver/internal/metadata/generated_config.go @@ -27,25 +27,33 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { // MetricsConfig provides config for nginx metrics. type MetricsConfig struct { - NginxConnectionsAccepted MetricConfig `mapstructure:"nginx.connections_accepted"` - NginxConnectionsCurrent MetricConfig `mapstructure:"nginx.connections_current"` - NginxConnectionsHandled MetricConfig `mapstructure:"nginx.connections_handled"` - NginxLoadTimestamp MetricConfig `mapstructure:"nginx.load_timestamp"` - NginxNetReading MetricConfig `mapstructure:"nginx.net.reading"` - NginxNetWaiting MetricConfig `mapstructure:"nginx.net.waiting"` - NginxNetWriting MetricConfig `mapstructure:"nginx.net.writing"` - NginxRequests MetricConfig `mapstructure:"nginx.requests"` - NginxServerZoneReceived MetricConfig `mapstructure:"nginx.server_zone.received"` - NginxServerZoneResponses1xx MetricConfig `mapstructure:"nginx.server_zone.responses.1xx"` - NginxServerZoneResponses2xx MetricConfig `mapstructure:"nginx.server_zone.responses.2xx"` - NginxServerZoneResponses3xx MetricConfig `mapstructure:"nginx.server_zone.responses.3xx"` - NginxServerZoneResponses4xx MetricConfig `mapstructure:"nginx.server_zone.responses.4xx"` - NginxServerZoneResponses5xx MetricConfig `mapstructure:"nginx.server_zone.responses.5xx"` - NginxServerZoneSent MetricConfig `mapstructure:"nginx.server_zone.sent"` - NginxUpstreamPeersReceived MetricConfig `mapstructure:"nginx.upstream.peers.received"` - NginxUpstreamPeersRequests MetricConfig `mapstructure:"nginx.upstream.peers.requests"` - NginxUpstreamPeersResponseTime MetricConfig `mapstructure:"nginx.upstream.peers.response_time"` - NginxUpstreamPeersSent MetricConfig `mapstructure:"nginx.upstream.peers.sent"` + NginxConnectionsAccepted MetricConfig `mapstructure:"nginx.connections_accepted"` + NginxConnectionsCurrent MetricConfig `mapstructure:"nginx.connections_current"` + NginxConnectionsHandled MetricConfig `mapstructure:"nginx.connections_handled"` + NginxLoadTimestamp MetricConfig `mapstructure:"nginx.load_timestamp"` + NginxNetReading MetricConfig `mapstructure:"nginx.net.reading"` + NginxNetWaiting MetricConfig `mapstructure:"nginx.net.waiting"` + NginxNetWriting MetricConfig `mapstructure:"nginx.net.writing"` + NginxRequests MetricConfig `mapstructure:"nginx.requests"` + NginxServerZoneReceived MetricConfig `mapstructure:"nginx.server_zone.received"` + NginxServerZoneResponses1xx MetricConfig `mapstructure:"nginx.server_zone.responses.1xx"` + NginxServerZoneResponses2xx MetricConfig `mapstructure:"nginx.server_zone.responses.2xx"` + NginxServerZoneResponses3xx MetricConfig `mapstructure:"nginx.server_zone.responses.3xx"` + NginxServerZoneResponses4xx MetricConfig `mapstructure:"nginx.server_zone.responses.4xx"` + NginxServerZoneResponses5xx MetricConfig `mapstructure:"nginx.server_zone.responses.5xx"` + NginxServerZoneSent MetricConfig `mapstructure:"nginx.server_zone.sent"` + NginxUpstreamPeersBackup MetricConfig `mapstructure:"nginx.upstream.peers.backup"` + NginxUpstreamPeersHealthChecksLastPassed MetricConfig `mapstructure:"nginx.upstream.peers.health_checks.last_passed"` + NginxUpstreamPeersReceived MetricConfig `mapstructure:"nginx.upstream.peers.received"` + NginxUpstreamPeersRequests MetricConfig `mapstructure:"nginx.upstream.peers.requests"` + NginxUpstreamPeersResponseTime MetricConfig `mapstructure:"nginx.upstream.peers.response_time"` + NginxUpstreamPeersResponses1xx MetricConfig `mapstructure:"nginx.upstream.peers.responses.1xx"` + NginxUpstreamPeersResponses2xx MetricConfig `mapstructure:"nginx.upstream.peers.responses.2xx"` + NginxUpstreamPeersResponses3xx MetricConfig `mapstructure:"nginx.upstream.peers.responses.3xx"` + NginxUpstreamPeersResponses4xx MetricConfig `mapstructure:"nginx.upstream.peers.responses.4xx"` + NginxUpstreamPeersResponses5xx MetricConfig `mapstructure:"nginx.upstream.peers.responses.5xx"` + NginxUpstreamPeersSent MetricConfig `mapstructure:"nginx.upstream.peers.sent"` + NginxUpstreamPeersWeight MetricConfig `mapstructure:"nginx.upstream.peers.weight"` } func DefaultMetricsConfig() MetricsConfig { @@ -95,6 +103,12 @@ func DefaultMetricsConfig() MetricsConfig { NginxServerZoneSent: MetricConfig{ Enabled: true, }, + NginxUpstreamPeersBackup: MetricConfig{ + Enabled: true, + }, + NginxUpstreamPeersHealthChecksLastPassed: MetricConfig{ + Enabled: true, + }, NginxUpstreamPeersReceived: MetricConfig{ Enabled: true, }, @@ -104,9 +118,27 @@ func DefaultMetricsConfig() MetricsConfig { NginxUpstreamPeersResponseTime: MetricConfig{ Enabled: true, }, + NginxUpstreamPeersResponses1xx: MetricConfig{ + Enabled: true, + }, + NginxUpstreamPeersResponses2xx: MetricConfig{ + Enabled: true, + }, + NginxUpstreamPeersResponses3xx: MetricConfig{ + Enabled: true, + }, + NginxUpstreamPeersResponses4xx: MetricConfig{ + Enabled: true, + }, + NginxUpstreamPeersResponses5xx: MetricConfig{ + Enabled: true, + }, NginxUpstreamPeersSent: MetricConfig{ Enabled: true, }, + NginxUpstreamPeersWeight: MetricConfig{ + Enabled: true, + }, } } diff --git a/receiver/nginxreceiver/internal/metadata/generated_config_test.go b/receiver/nginxreceiver/internal/metadata/generated_config_test.go index 30a9c7c7ce11..9403275ba450 100644 --- a/receiver/nginxreceiver/internal/metadata/generated_config_test.go +++ b/receiver/nginxreceiver/internal/metadata/generated_config_test.go @@ -25,25 +25,33 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "all_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ - NginxConnectionsAccepted: MetricConfig{Enabled: true}, - NginxConnectionsCurrent: MetricConfig{Enabled: true}, - NginxConnectionsHandled: MetricConfig{Enabled: true}, - NginxLoadTimestamp: MetricConfig{Enabled: true}, - NginxNetReading: MetricConfig{Enabled: true}, - NginxNetWaiting: MetricConfig{Enabled: true}, - NginxNetWriting: MetricConfig{Enabled: true}, - NginxRequests: MetricConfig{Enabled: true}, - NginxServerZoneReceived: MetricConfig{Enabled: true}, - NginxServerZoneResponses1xx: MetricConfig{Enabled: true}, - NginxServerZoneResponses2xx: MetricConfig{Enabled: true}, - NginxServerZoneResponses3xx: MetricConfig{Enabled: true}, - NginxServerZoneResponses4xx: MetricConfig{Enabled: true}, - NginxServerZoneResponses5xx: MetricConfig{Enabled: true}, - NginxServerZoneSent: MetricConfig{Enabled: true}, - NginxUpstreamPeersReceived: MetricConfig{Enabled: true}, - NginxUpstreamPeersRequests: MetricConfig{Enabled: true}, - NginxUpstreamPeersResponseTime: MetricConfig{Enabled: true}, - NginxUpstreamPeersSent: MetricConfig{Enabled: true}, + NginxConnectionsAccepted: MetricConfig{Enabled: true}, + NginxConnectionsCurrent: MetricConfig{Enabled: true}, + NginxConnectionsHandled: MetricConfig{Enabled: true}, + NginxLoadTimestamp: MetricConfig{Enabled: true}, + NginxNetReading: MetricConfig{Enabled: true}, + NginxNetWaiting: MetricConfig{Enabled: true}, + NginxNetWriting: MetricConfig{Enabled: true}, + NginxRequests: MetricConfig{Enabled: true}, + NginxServerZoneReceived: MetricConfig{Enabled: true}, + NginxServerZoneResponses1xx: MetricConfig{Enabled: true}, + NginxServerZoneResponses2xx: MetricConfig{Enabled: true}, + NginxServerZoneResponses3xx: MetricConfig{Enabled: true}, + NginxServerZoneResponses4xx: MetricConfig{Enabled: true}, + NginxServerZoneResponses5xx: MetricConfig{Enabled: true}, + NginxServerZoneSent: MetricConfig{Enabled: true}, + NginxUpstreamPeersBackup: MetricConfig{Enabled: true}, + NginxUpstreamPeersHealthChecksLastPassed: MetricConfig{Enabled: true}, + NginxUpstreamPeersReceived: MetricConfig{Enabled: true}, + NginxUpstreamPeersRequests: MetricConfig{Enabled: true}, + NginxUpstreamPeersResponseTime: MetricConfig{Enabled: true}, + NginxUpstreamPeersResponses1xx: MetricConfig{Enabled: true}, + NginxUpstreamPeersResponses2xx: MetricConfig{Enabled: true}, + NginxUpstreamPeersResponses3xx: MetricConfig{Enabled: true}, + NginxUpstreamPeersResponses4xx: MetricConfig{Enabled: true}, + NginxUpstreamPeersResponses5xx: MetricConfig{Enabled: true}, + NginxUpstreamPeersSent: MetricConfig{Enabled: true}, + NginxUpstreamPeersWeight: MetricConfig{Enabled: true}, }, }, }, @@ -51,25 +59,33 @@ func TestMetricsBuilderConfig(t *testing.T) { name: "none_set", want: MetricsBuilderConfig{ Metrics: MetricsConfig{ - NginxConnectionsAccepted: MetricConfig{Enabled: false}, - NginxConnectionsCurrent: MetricConfig{Enabled: false}, - NginxConnectionsHandled: MetricConfig{Enabled: false}, - NginxLoadTimestamp: MetricConfig{Enabled: false}, - NginxNetReading: MetricConfig{Enabled: false}, - NginxNetWaiting: MetricConfig{Enabled: false}, - NginxNetWriting: MetricConfig{Enabled: false}, - NginxRequests: MetricConfig{Enabled: false}, - NginxServerZoneReceived: MetricConfig{Enabled: false}, - NginxServerZoneResponses1xx: MetricConfig{Enabled: false}, - NginxServerZoneResponses2xx: MetricConfig{Enabled: false}, - NginxServerZoneResponses3xx: MetricConfig{Enabled: false}, - NginxServerZoneResponses4xx: MetricConfig{Enabled: false}, - NginxServerZoneResponses5xx: MetricConfig{Enabled: false}, - NginxServerZoneSent: MetricConfig{Enabled: false}, - NginxUpstreamPeersReceived: MetricConfig{Enabled: false}, - NginxUpstreamPeersRequests: MetricConfig{Enabled: false}, - NginxUpstreamPeersResponseTime: MetricConfig{Enabled: false}, - NginxUpstreamPeersSent: MetricConfig{Enabled: false}, + NginxConnectionsAccepted: MetricConfig{Enabled: false}, + NginxConnectionsCurrent: MetricConfig{Enabled: false}, + NginxConnectionsHandled: MetricConfig{Enabled: false}, + NginxLoadTimestamp: MetricConfig{Enabled: false}, + NginxNetReading: MetricConfig{Enabled: false}, + NginxNetWaiting: MetricConfig{Enabled: false}, + NginxNetWriting: MetricConfig{Enabled: false}, + NginxRequests: MetricConfig{Enabled: false}, + NginxServerZoneReceived: MetricConfig{Enabled: false}, + NginxServerZoneResponses1xx: MetricConfig{Enabled: false}, + NginxServerZoneResponses2xx: MetricConfig{Enabled: false}, + NginxServerZoneResponses3xx: MetricConfig{Enabled: false}, + NginxServerZoneResponses4xx: MetricConfig{Enabled: false}, + NginxServerZoneResponses5xx: MetricConfig{Enabled: false}, + NginxServerZoneSent: MetricConfig{Enabled: false}, + NginxUpstreamPeersBackup: MetricConfig{Enabled: false}, + NginxUpstreamPeersHealthChecksLastPassed: MetricConfig{Enabled: false}, + NginxUpstreamPeersReceived: MetricConfig{Enabled: false}, + NginxUpstreamPeersRequests: MetricConfig{Enabled: false}, + NginxUpstreamPeersResponseTime: MetricConfig{Enabled: false}, + NginxUpstreamPeersResponses1xx: MetricConfig{Enabled: false}, + NginxUpstreamPeersResponses2xx: MetricConfig{Enabled: false}, + NginxUpstreamPeersResponses3xx: MetricConfig{Enabled: false}, + NginxUpstreamPeersResponses4xx: MetricConfig{Enabled: false}, + NginxUpstreamPeersResponses5xx: MetricConfig{Enabled: false}, + NginxUpstreamPeersSent: MetricConfig{Enabled: false}, + NginxUpstreamPeersWeight: MetricConfig{Enabled: false}, }, }, }, diff --git a/receiver/nginxreceiver/internal/metadata/generated_metrics.go b/receiver/nginxreceiver/internal/metadata/generated_metrics.go index ce9d8b540c7f..2d3e96dfeb2d 100644 --- a/receiver/nginxreceiver/internal/metadata/generated_metrics.go +++ b/receiver/nginxreceiver/internal/metadata/generated_metrics.go @@ -808,6 +808,110 @@ func newMetricNginxServerZoneSent(cfg MetricConfig) metricNginxServerZoneSent { return m } +type metricNginxUpstreamPeersBackup struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills nginx.upstream.peers.backup metric with initial data. +func (m *metricNginxUpstreamPeersBackup) init() { + m.data.SetName("nginx.upstream.peers.backup") + m.data.SetDescription("Whether upstream server is a backup server") + m.data.SetUnit("{state}") + m.data.SetEmptyGauge() + m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricNginxUpstreamPeersBackup) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("upstream_block_name", upstreamBlockNameAttributeValue) + dp.Attributes().PutStr("upstream_peer_address", upstreamPeerAddressAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricNginxUpstreamPeersBackup) updateCapacity() { + if m.data.Gauge().DataPoints().Len() > m.capacity { + m.capacity = m.data.Gauge().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricNginxUpstreamPeersBackup) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricNginxUpstreamPeersBackup(cfg MetricConfig) metricNginxUpstreamPeersBackup { + m := metricNginxUpstreamPeersBackup{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricNginxUpstreamPeersHealthChecksLastPassed struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills nginx.upstream.peers.health_checks.last_passed metric with initial data. +func (m *metricNginxUpstreamPeersHealthChecksLastPassed) init() { + m.data.SetName("nginx.upstream.peers.health_checks.last_passed") + m.data.SetDescription("Boolean indicating if the last health check request was successful and passed tests.") + m.data.SetUnit("{status}") + m.data.SetEmptyGauge() + m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricNginxUpstreamPeersHealthChecksLastPassed) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("upstream_block_name", upstreamBlockNameAttributeValue) + dp.Attributes().PutStr("upstream_peer_address", upstreamPeerAddressAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricNginxUpstreamPeersHealthChecksLastPassed) updateCapacity() { + if m.data.Gauge().DataPoints().Len() > m.capacity { + m.capacity = m.data.Gauge().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricNginxUpstreamPeersHealthChecksLastPassed) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricNginxUpstreamPeersHealthChecksLastPassed(cfg MetricConfig) metricNginxUpstreamPeersHealthChecksLastPassed { + m := metricNginxUpstreamPeersHealthChecksLastPassed{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricNginxUpstreamPeersReceived struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -968,6 +1072,276 @@ func newMetricNginxUpstreamPeersResponseTime(cfg MetricConfig) metricNginxUpstre return m } +type metricNginxUpstreamPeersResponses1xx struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills nginx.upstream.peers.responses.1xx metric with initial data. +func (m *metricNginxUpstreamPeersResponses1xx) init() { + m.data.SetName("nginx.upstream.peers.responses.1xx") + m.data.SetDescription("Number of responses from upstream with 1xx status codes") + m.data.SetUnit("responses") + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricNginxUpstreamPeersResponses1xx) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("upstream_block_name", upstreamBlockNameAttributeValue) + dp.Attributes().PutStr("upstream_peer_address", upstreamPeerAddressAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricNginxUpstreamPeersResponses1xx) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricNginxUpstreamPeersResponses1xx) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricNginxUpstreamPeersResponses1xx(cfg MetricConfig) metricNginxUpstreamPeersResponses1xx { + m := metricNginxUpstreamPeersResponses1xx{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricNginxUpstreamPeersResponses2xx struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills nginx.upstream.peers.responses.2xx metric with initial data. +func (m *metricNginxUpstreamPeersResponses2xx) init() { + m.data.SetName("nginx.upstream.peers.responses.2xx") + m.data.SetDescription("Number of responses from upstream with 2xx status codes") + m.data.SetUnit("responses") + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricNginxUpstreamPeersResponses2xx) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("upstream_block_name", upstreamBlockNameAttributeValue) + dp.Attributes().PutStr("upstream_peer_address", upstreamPeerAddressAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricNginxUpstreamPeersResponses2xx) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricNginxUpstreamPeersResponses2xx) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricNginxUpstreamPeersResponses2xx(cfg MetricConfig) metricNginxUpstreamPeersResponses2xx { + m := metricNginxUpstreamPeersResponses2xx{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricNginxUpstreamPeersResponses3xx struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills nginx.upstream.peers.responses.3xx metric with initial data. +func (m *metricNginxUpstreamPeersResponses3xx) init() { + m.data.SetName("nginx.upstream.peers.responses.3xx") + m.data.SetDescription("Number of responses from upstream with 3xx status codes") + m.data.SetUnit("responses") + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricNginxUpstreamPeersResponses3xx) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("upstream_block_name", upstreamBlockNameAttributeValue) + dp.Attributes().PutStr("upstream_peer_address", upstreamPeerAddressAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricNginxUpstreamPeersResponses3xx) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricNginxUpstreamPeersResponses3xx) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricNginxUpstreamPeersResponses3xx(cfg MetricConfig) metricNginxUpstreamPeersResponses3xx { + m := metricNginxUpstreamPeersResponses3xx{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricNginxUpstreamPeersResponses4xx struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills nginx.upstream.peers.responses.4xx metric with initial data. +func (m *metricNginxUpstreamPeersResponses4xx) init() { + m.data.SetName("nginx.upstream.peers.responses.4xx") + m.data.SetDescription("Number of responses from upstream with 4xx status codes") + m.data.SetUnit("responses") + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricNginxUpstreamPeersResponses4xx) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("upstream_block_name", upstreamBlockNameAttributeValue) + dp.Attributes().PutStr("upstream_peer_address", upstreamPeerAddressAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricNginxUpstreamPeersResponses4xx) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricNginxUpstreamPeersResponses4xx) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricNginxUpstreamPeersResponses4xx(cfg MetricConfig) metricNginxUpstreamPeersResponses4xx { + m := metricNginxUpstreamPeersResponses4xx{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + +type metricNginxUpstreamPeersResponses5xx struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills nginx.upstream.peers.responses.5xx metric with initial data. +func (m *metricNginxUpstreamPeersResponses5xx) init() { + m.data.SetName("nginx.upstream.peers.responses.5xx") + m.data.SetDescription("Number of responses from upstream with 5xx status codes") + m.data.SetUnit("responses") + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(true) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricNginxUpstreamPeersResponses5xx) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Sum().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetIntValue(val) + dp.Attributes().PutStr("upstream_block_name", upstreamBlockNameAttributeValue) + dp.Attributes().PutStr("upstream_peer_address", upstreamPeerAddressAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricNginxUpstreamPeersResponses5xx) updateCapacity() { + if m.data.Sum().DataPoints().Len() > m.capacity { + m.capacity = m.data.Sum().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricNginxUpstreamPeersResponses5xx) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricNginxUpstreamPeersResponses5xx(cfg MetricConfig) metricNginxUpstreamPeersResponses5xx { + m := metricNginxUpstreamPeersResponses5xx{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + type metricNginxUpstreamPeersSent struct { data pmetric.Metric // data buffer for generated metric. config MetricConfig // metric config provided by user. @@ -1022,33 +1396,93 @@ func newMetricNginxUpstreamPeersSent(cfg MetricConfig) metricNginxUpstreamPeersS return m } +type metricNginxUpstreamPeersWeight struct { + data pmetric.Metric // data buffer for generated metric. + config MetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. +} + +// init fills nginx.upstream.peers.weight metric with initial data. +func (m *metricNginxUpstreamPeersWeight) init() { + m.data.SetName("nginx.upstream.peers.weight") + m.data.SetDescription("Weight of upstream server") + m.data.SetUnit("weight") + m.data.SetEmptyGauge() + m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) +} + +func (m *metricNginxUpstreamPeersWeight) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val float64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + if !m.config.Enabled { + return + } + dp := m.data.Gauge().DataPoints().AppendEmpty() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + dp.SetDoubleValue(val) + dp.Attributes().PutStr("upstream_block_name", upstreamBlockNameAttributeValue) + dp.Attributes().PutStr("upstream_peer_address", upstreamPeerAddressAttributeValue) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricNginxUpstreamPeersWeight) updateCapacity() { + if m.data.Gauge().DataPoints().Len() > m.capacity { + m.capacity = m.data.Gauge().DataPoints().Len() + } +} + +// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. +func (m *metricNginxUpstreamPeersWeight) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricNginxUpstreamPeersWeight(cfg MetricConfig) metricNginxUpstreamPeersWeight { + m := metricNginxUpstreamPeersWeight{config: cfg} + if cfg.Enabled { + m.data = pmetric.NewMetric() + m.init() + } + return m +} + // MetricsBuilder provides an interface for scrapers to report metrics while taking care of all the transformations // required to produce metric representation defined in metadata and user config. type MetricsBuilder struct { - config MetricsBuilderConfig // config of the metrics builder. - startTime pcommon.Timestamp // start time that will be applied to all recorded data points. - metricsCapacity int // maximum observed number of metrics per resource. - metricsBuffer pmetric.Metrics // accumulates metrics data before emitting. - buildInfo component.BuildInfo // contains version information. - metricNginxConnectionsAccepted metricNginxConnectionsAccepted - metricNginxConnectionsCurrent metricNginxConnectionsCurrent - metricNginxConnectionsHandled metricNginxConnectionsHandled - metricNginxLoadTimestamp metricNginxLoadTimestamp - metricNginxNetReading metricNginxNetReading - metricNginxNetWaiting metricNginxNetWaiting - metricNginxNetWriting metricNginxNetWriting - metricNginxRequests metricNginxRequests - metricNginxServerZoneReceived metricNginxServerZoneReceived - metricNginxServerZoneResponses1xx metricNginxServerZoneResponses1xx - metricNginxServerZoneResponses2xx metricNginxServerZoneResponses2xx - metricNginxServerZoneResponses3xx metricNginxServerZoneResponses3xx - metricNginxServerZoneResponses4xx metricNginxServerZoneResponses4xx - metricNginxServerZoneResponses5xx metricNginxServerZoneResponses5xx - metricNginxServerZoneSent metricNginxServerZoneSent - metricNginxUpstreamPeersReceived metricNginxUpstreamPeersReceived - metricNginxUpstreamPeersRequests metricNginxUpstreamPeersRequests - metricNginxUpstreamPeersResponseTime metricNginxUpstreamPeersResponseTime - metricNginxUpstreamPeersSent metricNginxUpstreamPeersSent + config MetricsBuilderConfig // config of the metrics builder. + startTime pcommon.Timestamp // start time that will be applied to all recorded data points. + metricsCapacity int // maximum observed number of metrics per resource. + metricsBuffer pmetric.Metrics // accumulates metrics data before emitting. + buildInfo component.BuildInfo // contains version information. + metricNginxConnectionsAccepted metricNginxConnectionsAccepted + metricNginxConnectionsCurrent metricNginxConnectionsCurrent + metricNginxConnectionsHandled metricNginxConnectionsHandled + metricNginxLoadTimestamp metricNginxLoadTimestamp + metricNginxNetReading metricNginxNetReading + metricNginxNetWaiting metricNginxNetWaiting + metricNginxNetWriting metricNginxNetWriting + metricNginxRequests metricNginxRequests + metricNginxServerZoneReceived metricNginxServerZoneReceived + metricNginxServerZoneResponses1xx metricNginxServerZoneResponses1xx + metricNginxServerZoneResponses2xx metricNginxServerZoneResponses2xx + metricNginxServerZoneResponses3xx metricNginxServerZoneResponses3xx + metricNginxServerZoneResponses4xx metricNginxServerZoneResponses4xx + metricNginxServerZoneResponses5xx metricNginxServerZoneResponses5xx + metricNginxServerZoneSent metricNginxServerZoneSent + metricNginxUpstreamPeersBackup metricNginxUpstreamPeersBackup + metricNginxUpstreamPeersHealthChecksLastPassed metricNginxUpstreamPeersHealthChecksLastPassed + metricNginxUpstreamPeersReceived metricNginxUpstreamPeersReceived + metricNginxUpstreamPeersRequests metricNginxUpstreamPeersRequests + metricNginxUpstreamPeersResponseTime metricNginxUpstreamPeersResponseTime + metricNginxUpstreamPeersResponses1xx metricNginxUpstreamPeersResponses1xx + metricNginxUpstreamPeersResponses2xx metricNginxUpstreamPeersResponses2xx + metricNginxUpstreamPeersResponses3xx metricNginxUpstreamPeersResponses3xx + metricNginxUpstreamPeersResponses4xx metricNginxUpstreamPeersResponses4xx + metricNginxUpstreamPeersResponses5xx metricNginxUpstreamPeersResponses5xx + metricNginxUpstreamPeersSent metricNginxUpstreamPeersSent + metricNginxUpstreamPeersWeight metricNginxUpstreamPeersWeight } // metricBuilderOption applies changes to default metrics builder. @@ -1063,29 +1497,37 @@ func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, options ...metricBuilderOption) *MetricsBuilder { mb := &MetricsBuilder{ - config: mbc, - startTime: pcommon.NewTimestampFromTime(time.Now()), - metricsBuffer: pmetric.NewMetrics(), - buildInfo: settings.BuildInfo, - metricNginxConnectionsAccepted: newMetricNginxConnectionsAccepted(mbc.Metrics.NginxConnectionsAccepted), - metricNginxConnectionsCurrent: newMetricNginxConnectionsCurrent(mbc.Metrics.NginxConnectionsCurrent), - metricNginxConnectionsHandled: newMetricNginxConnectionsHandled(mbc.Metrics.NginxConnectionsHandled), - metricNginxLoadTimestamp: newMetricNginxLoadTimestamp(mbc.Metrics.NginxLoadTimestamp), - metricNginxNetReading: newMetricNginxNetReading(mbc.Metrics.NginxNetReading), - metricNginxNetWaiting: newMetricNginxNetWaiting(mbc.Metrics.NginxNetWaiting), - metricNginxNetWriting: newMetricNginxNetWriting(mbc.Metrics.NginxNetWriting), - metricNginxRequests: newMetricNginxRequests(mbc.Metrics.NginxRequests), - metricNginxServerZoneReceived: newMetricNginxServerZoneReceived(mbc.Metrics.NginxServerZoneReceived), - metricNginxServerZoneResponses1xx: newMetricNginxServerZoneResponses1xx(mbc.Metrics.NginxServerZoneResponses1xx), - metricNginxServerZoneResponses2xx: newMetricNginxServerZoneResponses2xx(mbc.Metrics.NginxServerZoneResponses2xx), - metricNginxServerZoneResponses3xx: newMetricNginxServerZoneResponses3xx(mbc.Metrics.NginxServerZoneResponses3xx), - metricNginxServerZoneResponses4xx: newMetricNginxServerZoneResponses4xx(mbc.Metrics.NginxServerZoneResponses4xx), - metricNginxServerZoneResponses5xx: newMetricNginxServerZoneResponses5xx(mbc.Metrics.NginxServerZoneResponses5xx), - metricNginxServerZoneSent: newMetricNginxServerZoneSent(mbc.Metrics.NginxServerZoneSent), - metricNginxUpstreamPeersReceived: newMetricNginxUpstreamPeersReceived(mbc.Metrics.NginxUpstreamPeersReceived), - metricNginxUpstreamPeersRequests: newMetricNginxUpstreamPeersRequests(mbc.Metrics.NginxUpstreamPeersRequests), - metricNginxUpstreamPeersResponseTime: newMetricNginxUpstreamPeersResponseTime(mbc.Metrics.NginxUpstreamPeersResponseTime), - metricNginxUpstreamPeersSent: newMetricNginxUpstreamPeersSent(mbc.Metrics.NginxUpstreamPeersSent), + config: mbc, + startTime: pcommon.NewTimestampFromTime(time.Now()), + metricsBuffer: pmetric.NewMetrics(), + buildInfo: settings.BuildInfo, + metricNginxConnectionsAccepted: newMetricNginxConnectionsAccepted(mbc.Metrics.NginxConnectionsAccepted), + metricNginxConnectionsCurrent: newMetricNginxConnectionsCurrent(mbc.Metrics.NginxConnectionsCurrent), + metricNginxConnectionsHandled: newMetricNginxConnectionsHandled(mbc.Metrics.NginxConnectionsHandled), + metricNginxLoadTimestamp: newMetricNginxLoadTimestamp(mbc.Metrics.NginxLoadTimestamp), + metricNginxNetReading: newMetricNginxNetReading(mbc.Metrics.NginxNetReading), + metricNginxNetWaiting: newMetricNginxNetWaiting(mbc.Metrics.NginxNetWaiting), + metricNginxNetWriting: newMetricNginxNetWriting(mbc.Metrics.NginxNetWriting), + metricNginxRequests: newMetricNginxRequests(mbc.Metrics.NginxRequests), + metricNginxServerZoneReceived: newMetricNginxServerZoneReceived(mbc.Metrics.NginxServerZoneReceived), + metricNginxServerZoneResponses1xx: newMetricNginxServerZoneResponses1xx(mbc.Metrics.NginxServerZoneResponses1xx), + metricNginxServerZoneResponses2xx: newMetricNginxServerZoneResponses2xx(mbc.Metrics.NginxServerZoneResponses2xx), + metricNginxServerZoneResponses3xx: newMetricNginxServerZoneResponses3xx(mbc.Metrics.NginxServerZoneResponses3xx), + metricNginxServerZoneResponses4xx: newMetricNginxServerZoneResponses4xx(mbc.Metrics.NginxServerZoneResponses4xx), + metricNginxServerZoneResponses5xx: newMetricNginxServerZoneResponses5xx(mbc.Metrics.NginxServerZoneResponses5xx), + metricNginxServerZoneSent: newMetricNginxServerZoneSent(mbc.Metrics.NginxServerZoneSent), + metricNginxUpstreamPeersBackup: newMetricNginxUpstreamPeersBackup(mbc.Metrics.NginxUpstreamPeersBackup), + metricNginxUpstreamPeersHealthChecksLastPassed: newMetricNginxUpstreamPeersHealthChecksLastPassed(mbc.Metrics.NginxUpstreamPeersHealthChecksLastPassed), + metricNginxUpstreamPeersReceived: newMetricNginxUpstreamPeersReceived(mbc.Metrics.NginxUpstreamPeersReceived), + metricNginxUpstreamPeersRequests: newMetricNginxUpstreamPeersRequests(mbc.Metrics.NginxUpstreamPeersRequests), + metricNginxUpstreamPeersResponseTime: newMetricNginxUpstreamPeersResponseTime(mbc.Metrics.NginxUpstreamPeersResponseTime), + metricNginxUpstreamPeersResponses1xx: newMetricNginxUpstreamPeersResponses1xx(mbc.Metrics.NginxUpstreamPeersResponses1xx), + metricNginxUpstreamPeersResponses2xx: newMetricNginxUpstreamPeersResponses2xx(mbc.Metrics.NginxUpstreamPeersResponses2xx), + metricNginxUpstreamPeersResponses3xx: newMetricNginxUpstreamPeersResponses3xx(mbc.Metrics.NginxUpstreamPeersResponses3xx), + metricNginxUpstreamPeersResponses4xx: newMetricNginxUpstreamPeersResponses4xx(mbc.Metrics.NginxUpstreamPeersResponses4xx), + metricNginxUpstreamPeersResponses5xx: newMetricNginxUpstreamPeersResponses5xx(mbc.Metrics.NginxUpstreamPeersResponses5xx), + metricNginxUpstreamPeersSent: newMetricNginxUpstreamPeersSent(mbc.Metrics.NginxUpstreamPeersSent), + metricNginxUpstreamPeersWeight: newMetricNginxUpstreamPeersWeight(mbc.Metrics.NginxUpstreamPeersWeight), } for _, op := range options { @@ -1158,10 +1600,18 @@ func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { mb.metricNginxServerZoneResponses4xx.emit(ils.Metrics()) mb.metricNginxServerZoneResponses5xx.emit(ils.Metrics()) mb.metricNginxServerZoneSent.emit(ils.Metrics()) + mb.metricNginxUpstreamPeersBackup.emit(ils.Metrics()) + mb.metricNginxUpstreamPeersHealthChecksLastPassed.emit(ils.Metrics()) mb.metricNginxUpstreamPeersReceived.emit(ils.Metrics()) mb.metricNginxUpstreamPeersRequests.emit(ils.Metrics()) mb.metricNginxUpstreamPeersResponseTime.emit(ils.Metrics()) + mb.metricNginxUpstreamPeersResponses1xx.emit(ils.Metrics()) + mb.metricNginxUpstreamPeersResponses2xx.emit(ils.Metrics()) + mb.metricNginxUpstreamPeersResponses3xx.emit(ils.Metrics()) + mb.metricNginxUpstreamPeersResponses4xx.emit(ils.Metrics()) + mb.metricNginxUpstreamPeersResponses5xx.emit(ils.Metrics()) mb.metricNginxUpstreamPeersSent.emit(ils.Metrics()) + mb.metricNginxUpstreamPeersWeight.emit(ils.Metrics()) for _, op := range rmo { op(rm) @@ -1258,6 +1708,16 @@ func (mb *MetricsBuilder) RecordNginxServerZoneSentDataPoint(ts pcommon.Timestam mb.metricNginxServerZoneSent.recordDataPoint(mb.startTime, ts, val, serverzoneNameAttributeValue) } +// RecordNginxUpstreamPeersBackupDataPoint adds a data point to nginx.upstream.peers.backup metric. +func (mb *MetricsBuilder) RecordNginxUpstreamPeersBackupDataPoint(ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + mb.metricNginxUpstreamPeersBackup.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) +} + +// RecordNginxUpstreamPeersHealthChecksLastPassedDataPoint adds a data point to nginx.upstream.peers.health_checks.last_passed metric. +func (mb *MetricsBuilder) RecordNginxUpstreamPeersHealthChecksLastPassedDataPoint(ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + mb.metricNginxUpstreamPeersHealthChecksLastPassed.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) +} + // RecordNginxUpstreamPeersReceivedDataPoint adds a data point to nginx.upstream.peers.received metric. func (mb *MetricsBuilder) RecordNginxUpstreamPeersReceivedDataPoint(ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { mb.metricNginxUpstreamPeersReceived.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) @@ -1273,11 +1733,41 @@ func (mb *MetricsBuilder) RecordNginxUpstreamPeersResponseTimeDataPoint(ts pcomm mb.metricNginxUpstreamPeersResponseTime.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) } +// RecordNginxUpstreamPeersResponses1xxDataPoint adds a data point to nginx.upstream.peers.responses.1xx metric. +func (mb *MetricsBuilder) RecordNginxUpstreamPeersResponses1xxDataPoint(ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + mb.metricNginxUpstreamPeersResponses1xx.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) +} + +// RecordNginxUpstreamPeersResponses2xxDataPoint adds a data point to nginx.upstream.peers.responses.2xx metric. +func (mb *MetricsBuilder) RecordNginxUpstreamPeersResponses2xxDataPoint(ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + mb.metricNginxUpstreamPeersResponses2xx.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) +} + +// RecordNginxUpstreamPeersResponses3xxDataPoint adds a data point to nginx.upstream.peers.responses.3xx metric. +func (mb *MetricsBuilder) RecordNginxUpstreamPeersResponses3xxDataPoint(ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + mb.metricNginxUpstreamPeersResponses3xx.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) +} + +// RecordNginxUpstreamPeersResponses4xxDataPoint adds a data point to nginx.upstream.peers.responses.4xx metric. +func (mb *MetricsBuilder) RecordNginxUpstreamPeersResponses4xxDataPoint(ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + mb.metricNginxUpstreamPeersResponses4xx.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) +} + +// RecordNginxUpstreamPeersResponses5xxDataPoint adds a data point to nginx.upstream.peers.responses.5xx metric. +func (mb *MetricsBuilder) RecordNginxUpstreamPeersResponses5xxDataPoint(ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + mb.metricNginxUpstreamPeersResponses5xx.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) +} + // RecordNginxUpstreamPeersSentDataPoint adds a data point to nginx.upstream.peers.sent metric. func (mb *MetricsBuilder) RecordNginxUpstreamPeersSentDataPoint(ts pcommon.Timestamp, val int64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { mb.metricNginxUpstreamPeersSent.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) } +// RecordNginxUpstreamPeersWeightDataPoint adds a data point to nginx.upstream.peers.weight metric. +func (mb *MetricsBuilder) RecordNginxUpstreamPeersWeightDataPoint(ts pcommon.Timestamp, val float64, upstreamBlockNameAttributeValue string, upstreamPeerAddressAttributeValue string) { + mb.metricNginxUpstreamPeersWeight.recordDataPoint(mb.startTime, ts, val, upstreamBlockNameAttributeValue, upstreamPeerAddressAttributeValue) +} + // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, // and metrics builder should update its startTime and reset it's internal state accordingly. func (mb *MetricsBuilder) Reset(options ...metricBuilderOption) { diff --git a/receiver/nginxreceiver/internal/metadata/generated_metrics_test.go b/receiver/nginxreceiver/internal/metadata/generated_metrics_test.go index d1111c33b734..b61298a0b9c4 100644 --- a/receiver/nginxreceiver/internal/metadata/generated_metrics_test.go +++ b/receiver/nginxreceiver/internal/metadata/generated_metrics_test.go @@ -119,6 +119,14 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordNginxServerZoneSentDataPoint(ts, 1, "serverzone_name-val") + defaultMetricsCount++ + allMetricsCount++ + mb.RecordNginxUpstreamPeersBackupDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + + defaultMetricsCount++ + allMetricsCount++ + mb.RecordNginxUpstreamPeersHealthChecksLastPassedDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + defaultMetricsCount++ allMetricsCount++ mb.RecordNginxUpstreamPeersReceivedDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") @@ -131,10 +139,34 @@ func TestMetricsBuilder(t *testing.T) { allMetricsCount++ mb.RecordNginxUpstreamPeersResponseTimeDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + defaultMetricsCount++ + allMetricsCount++ + mb.RecordNginxUpstreamPeersResponses1xxDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + + defaultMetricsCount++ + allMetricsCount++ + mb.RecordNginxUpstreamPeersResponses2xxDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + + defaultMetricsCount++ + allMetricsCount++ + mb.RecordNginxUpstreamPeersResponses3xxDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + + defaultMetricsCount++ + allMetricsCount++ + mb.RecordNginxUpstreamPeersResponses4xxDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + + defaultMetricsCount++ + allMetricsCount++ + mb.RecordNginxUpstreamPeersResponses5xxDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + defaultMetricsCount++ allMetricsCount++ mb.RecordNginxUpstreamPeersSentDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + defaultMetricsCount++ + allMetricsCount++ + mb.RecordNginxUpstreamPeersWeightDataPoint(ts, 1, "upstream_block_name-val", "upstream_peer_address-val") + res := pcommon.NewResource() metrics := mb.Emit(WithResource(res)) @@ -373,6 +405,42 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok := dp.Attributes().Get("serverzone_name") assert.True(t, ok) assert.EqualValues(t, "serverzone_name-val", attrVal.Str()) + case "nginx.upstream.peers.backup": + assert.False(t, validatedMetrics["nginx.upstream.peers.backup"], "Found a duplicate in the metrics slice: nginx.upstream.peers.backup") + validatedMetrics["nginx.upstream.peers.backup"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "Whether upstream server is a backup server", ms.At(i).Description()) + assert.Equal(t, "{state}", ms.At(i).Unit()) + dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) + attrVal, ok := dp.Attributes().Get("upstream_block_name") + assert.True(t, ok) + assert.EqualValues(t, "upstream_block_name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("upstream_peer_address") + assert.True(t, ok) + assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) + case "nginx.upstream.peers.health_checks.last_passed": + assert.False(t, validatedMetrics["nginx.upstream.peers.health_checks.last_passed"], "Found a duplicate in the metrics slice: nginx.upstream.peers.health_checks.last_passed") + validatedMetrics["nginx.upstream.peers.health_checks.last_passed"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "Boolean indicating if the last health check request was successful and passed tests.", ms.At(i).Description()) + assert.Equal(t, "{status}", ms.At(i).Unit()) + dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) + attrVal, ok := dp.Attributes().Get("upstream_block_name") + assert.True(t, ok) + assert.EqualValues(t, "upstream_block_name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("upstream_peer_address") + assert.True(t, ok) + assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) case "nginx.upstream.peers.received": assert.False(t, validatedMetrics["nginx.upstream.peers.received"], "Found a duplicate in the metrics slice: nginx.upstream.peers.received") validatedMetrics["nginx.upstream.peers.received"] = true @@ -431,6 +499,106 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("upstream_peer_address") assert.True(t, ok) assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) + case "nginx.upstream.peers.responses.1xx": + assert.False(t, validatedMetrics["nginx.upstream.peers.responses.1xx"], "Found a duplicate in the metrics slice: nginx.upstream.peers.responses.1xx") + validatedMetrics["nginx.upstream.peers.responses.1xx"] = true + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) + assert.Equal(t, "Number of responses from upstream with 1xx status codes", ms.At(i).Description()) + assert.Equal(t, "responses", ms.At(i).Unit()) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) + attrVal, ok := dp.Attributes().Get("upstream_block_name") + assert.True(t, ok) + assert.EqualValues(t, "upstream_block_name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("upstream_peer_address") + assert.True(t, ok) + assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) + case "nginx.upstream.peers.responses.2xx": + assert.False(t, validatedMetrics["nginx.upstream.peers.responses.2xx"], "Found a duplicate in the metrics slice: nginx.upstream.peers.responses.2xx") + validatedMetrics["nginx.upstream.peers.responses.2xx"] = true + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) + assert.Equal(t, "Number of responses from upstream with 2xx status codes", ms.At(i).Description()) + assert.Equal(t, "responses", ms.At(i).Unit()) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) + attrVal, ok := dp.Attributes().Get("upstream_block_name") + assert.True(t, ok) + assert.EqualValues(t, "upstream_block_name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("upstream_peer_address") + assert.True(t, ok) + assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) + case "nginx.upstream.peers.responses.3xx": + assert.False(t, validatedMetrics["nginx.upstream.peers.responses.3xx"], "Found a duplicate in the metrics slice: nginx.upstream.peers.responses.3xx") + validatedMetrics["nginx.upstream.peers.responses.3xx"] = true + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) + assert.Equal(t, "Number of responses from upstream with 3xx status codes", ms.At(i).Description()) + assert.Equal(t, "responses", ms.At(i).Unit()) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) + attrVal, ok := dp.Attributes().Get("upstream_block_name") + assert.True(t, ok) + assert.EqualValues(t, "upstream_block_name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("upstream_peer_address") + assert.True(t, ok) + assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) + case "nginx.upstream.peers.responses.4xx": + assert.False(t, validatedMetrics["nginx.upstream.peers.responses.4xx"], "Found a duplicate in the metrics slice: nginx.upstream.peers.responses.4xx") + validatedMetrics["nginx.upstream.peers.responses.4xx"] = true + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) + assert.Equal(t, "Number of responses from upstream with 4xx status codes", ms.At(i).Description()) + assert.Equal(t, "responses", ms.At(i).Unit()) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) + attrVal, ok := dp.Attributes().Get("upstream_block_name") + assert.True(t, ok) + assert.EqualValues(t, "upstream_block_name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("upstream_peer_address") + assert.True(t, ok) + assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) + case "nginx.upstream.peers.responses.5xx": + assert.False(t, validatedMetrics["nginx.upstream.peers.responses.5xx"], "Found a duplicate in the metrics slice: nginx.upstream.peers.responses.5xx") + validatedMetrics["nginx.upstream.peers.responses.5xx"] = true + assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) + assert.Equal(t, "Number of responses from upstream with 5xx status codes", ms.At(i).Description()) + assert.Equal(t, "responses", ms.At(i).Unit()) + assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) + dp := ms.At(i).Sum().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + assert.Equal(t, int64(1), dp.IntValue()) + attrVal, ok := dp.Attributes().Get("upstream_block_name") + assert.True(t, ok) + assert.EqualValues(t, "upstream_block_name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("upstream_peer_address") + assert.True(t, ok) + assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) case "nginx.upstream.peers.sent": assert.False(t, validatedMetrics["nginx.upstream.peers.sent"], "Found a duplicate in the metrics slice: nginx.upstream.peers.sent") validatedMetrics["nginx.upstream.peers.sent"] = true @@ -451,6 +619,24 @@ func TestMetricsBuilder(t *testing.T) { attrVal, ok = dp.Attributes().Get("upstream_peer_address") assert.True(t, ok) assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) + case "nginx.upstream.peers.weight": + assert.False(t, validatedMetrics["nginx.upstream.peers.weight"], "Found a duplicate in the metrics slice: nginx.upstream.peers.weight") + validatedMetrics["nginx.upstream.peers.weight"] = true + assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) + assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) + assert.Equal(t, "Weight of upstream server", ms.At(i).Description()) + assert.Equal(t, "weight", ms.At(i).Unit()) + dp := ms.At(i).Gauge().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) + assert.Equal(t, float64(1), dp.DoubleValue()) + attrVal, ok := dp.Attributes().Get("upstream_block_name") + assert.True(t, ok) + assert.EqualValues(t, "upstream_block_name-val", attrVal.Str()) + attrVal, ok = dp.Attributes().Get("upstream_peer_address") + assert.True(t, ok) + assert.EqualValues(t, "upstream_peer_address-val", attrVal.Str()) } } }) diff --git a/receiver/nginxreceiver/internal/metadata/testdata/config.yaml b/receiver/nginxreceiver/internal/metadata/testdata/config.yaml index 6df5912e1437..3a896e7cdadd 100644 --- a/receiver/nginxreceiver/internal/metadata/testdata/config.yaml +++ b/receiver/nginxreceiver/internal/metadata/testdata/config.yaml @@ -31,14 +31,30 @@ all_set: enabled: true nginx.server_zone.sent: enabled: true + nginx.upstream.peers.backup: + enabled: true + nginx.upstream.peers.health_checks.last_passed: + enabled: true nginx.upstream.peers.received: enabled: true nginx.upstream.peers.requests: enabled: true nginx.upstream.peers.response_time: enabled: true + nginx.upstream.peers.responses.1xx: + enabled: true + nginx.upstream.peers.responses.2xx: + enabled: true + nginx.upstream.peers.responses.3xx: + enabled: true + nginx.upstream.peers.responses.4xx: + enabled: true + nginx.upstream.peers.responses.5xx: + enabled: true nginx.upstream.peers.sent: enabled: true + nginx.upstream.peers.weight: + enabled: true none_set: metrics: nginx.connections_accepted: @@ -71,11 +87,27 @@ none_set: enabled: false nginx.server_zone.sent: enabled: false + nginx.upstream.peers.backup: + enabled: false + nginx.upstream.peers.health_checks.last_passed: + enabled: false nginx.upstream.peers.received: enabled: false nginx.upstream.peers.requests: enabled: false nginx.upstream.peers.response_time: enabled: false + nginx.upstream.peers.responses.1xx: + enabled: false + nginx.upstream.peers.responses.2xx: + enabled: false + nginx.upstream.peers.responses.3xx: + enabled: false + nginx.upstream.peers.responses.4xx: + enabled: false + nginx.upstream.peers.responses.5xx: + enabled: false nginx.upstream.peers.sent: enabled: false + nginx.upstream.peers.weight: + enabled: false diff --git a/receiver/nginxreceiver/metadata.yaml b/receiver/nginxreceiver/metadata.yaml index 1c7ce2f118d5..b51f5f2899d2 100644 --- a/receiver/nginxreceiver/metadata.yaml +++ b/receiver/nginxreceiver/metadata.yaml @@ -216,4 +216,106 @@ metrics: value_type: int monotonic: true aggregation_temporality: cumulative - unit: By \ No newline at end of file + unit: By + + ### Response Codes +# - `nginx.upstream.peers.responses.1xx` - Number of responses from upstream with 1xx status codes +# - `nginx.upstream.peers.responses.2xx` - Number of responses from upstream with 2xx status codes +# - `nginx.upstream.peers.responses.3xx` - Number of responses from upstream with 3xx status codes +# - `nginx.upstream.peers.responses.4xx` - Number of responses from upstream with 4xx status codes +# - `nginx.upstream.peers.responses.5xx` - Number of responses from upstream with 5xx status codes + + nginx.upstream.peers.responses.1xx: + enabled: true + attributes: + - upstream_block_name + - upstream_peer_address + description: Number of responses from upstream with 1xx status codes + sum: + value_type: int + monotonic: true + aggregation_temporality: cumulative + unit: responses + + nginx.upstream.peers.responses.2xx: + enabled: true + attributes: + - upstream_block_name + - upstream_peer_address + description: Number of responses from upstream with 2xx status codes + sum: + value_type: int + monotonic: true + aggregation_temporality: cumulative + unit: responses + + nginx.upstream.peers.responses.3xx: + enabled: true + attributes: + - upstream_block_name + - upstream_peer_address + description: Number of responses from upstream with 3xx status codes + sum: + value_type: int + monotonic: true + aggregation_temporality: cumulative + unit: responses + + nginx.upstream.peers.responses.4xx: + enabled: true + attributes: + - upstream_block_name + - upstream_peer_address + description: Number of responses from upstream with 4xx status codes + sum: + value_type: int + monotonic: true + aggregation_temporality: cumulative + unit: responses + + nginx.upstream.peers.responses.5xx: + enabled: true + attributes: + - upstream_block_name + - upstream_peer_address + description: Number of responses from upstream with 5xx status codes + sum: + value_type: int + monotonic: true + aggregation_temporality: cumulative + unit: responses + + ### Server Configuration +# - `nginx.upstream.peers.weight` - Weight of upstream server +# - `nginx.upstream.peers.backup` - Whether upstream server is a backup server +# - `nginx.upstream.peers.health_checks.last_passed` - Status of last health check for upstream server + + nginx.upstream.peers.weight: + enabled: true + attributes: + - upstream_block_name + - upstream_peer_address + description: Weight of upstream server + gauge: + value_type: double + unit: weight + + nginx.upstream.peers.backup: + enabled: true + attributes: + - upstream_block_name + - upstream_peer_address + description: Whether upstream server is a backup server + gauge: + value_type: int + unit: "{state}" + + nginx.upstream.peers.health_checks.last_passed: + enabled: true + attributes: + - upstream_block_name + - upstream_peer_address + description: Boolean indicating if the last health check request was successful and passed tests. + gauge: + value_type: int + unit: "{status}" \ No newline at end of file diff --git a/receiver/nginxreceiver/scraper.go b/receiver/nginxreceiver/scraper.go index 14e8c127fbe9..5ab3dfb3b762 100644 --- a/receiver/nginxreceiver/scraper.go +++ b/receiver/nginxreceiver/scraper.go @@ -96,18 +96,12 @@ func (r *nginxScraper) recordVtsStats(now pcommon.Timestamp, vtsStats *NginxVtsS r.recordVtsConnectionStats(now, vtsStats) r.recordVtsServerZoneResponseStats(now, vtsStats) r.recordVtsServerZoneTrafficStats(now, vtsStats) - r.recordVtsUpstreamRequestTrafficStats(now, vtsStats) + r.recordVtsUpstreamStats(now, vtsStats) } -func (r *nginxScraper) recordVtsUpstreamRequestTrafficStats(now pcommon.Timestamp, vtsStats *NginxVtsStatus) { +func (r *nginxScraper) recordVtsUpstreamStats(now pcommon.Timestamp, vtsStats *NginxVtsStatus) { for upstreamZoneName, upstreamZoneServers := range vtsStats.UpstreamZones { for _, upstreamZoneServer := range upstreamZoneServers { - // pp.Println(upstreamZoneName) - // pp.Println("Upstream Zone Server Address: ", upstreamZoneServer.Server) - // pp.Println("Reqs made to this server: ", upstreamZoneServer.RequestCounter) - // pp.Println("Bytes received by this server: ", upstreamZoneServer.InBytes) - // pp.Println("Bytes sent by this server: ", upstreamZoneServer.OutBytes) - r.mb.RecordNginxUpstreamPeersRequestsDataPoint( now, upstreamZoneServer.RequestCounter, upstreamZoneName, upstreamZoneServer.Server, ) @@ -117,6 +111,32 @@ func (r *nginxScraper) recordVtsUpstreamRequestTrafficStats(now pcommon.Timestam r.mb.RecordNginxUpstreamPeersSentDataPoint( now, upstreamZoneServer.OutBytes, upstreamZoneName, upstreamZoneServer.Server, ) + + r.mb.RecordNginxUpstreamPeersResponses1xxDataPoint( + now, upstreamZoneServer.Responses.Status1xx, upstreamZoneName, upstreamZoneServer.Server, + ) + r.mb.RecordNginxUpstreamPeersResponses2xxDataPoint( + now, upstreamZoneServer.Responses.Status2xx, upstreamZoneName, upstreamZoneServer.Server, + ) + r.mb.RecordNginxUpstreamPeersResponses3xxDataPoint( + now, upstreamZoneServer.Responses.Status3xx, upstreamZoneName, upstreamZoneServer.Server, + ) + r.mb.RecordNginxUpstreamPeersResponses4xxDataPoint( + now, upstreamZoneServer.Responses.Status4xx, upstreamZoneName, upstreamZoneServer.Server, + ) + r.mb.RecordNginxUpstreamPeersResponses5xxDataPoint( + now, upstreamZoneServer.Responses.Status5xx, upstreamZoneName, upstreamZoneServer.Server, + ) + + r.mb.RecordNginxUpstreamPeersWeightDataPoint( + now, upstreamZoneServer.Weight, upstreamZoneName, upstreamZoneServer.Server, + ) + r.mb.RecordNginxUpstreamPeersBackupDataPoint( + now, int64(boolToInt(upstreamZoneServer.Backup)), upstreamZoneName, upstreamZoneServer.Server, + ) + r.mb.RecordNginxUpstreamPeersHealthChecksLastPassedDataPoint( + now, int64(boolToInt(upstreamZoneServer.Down)), upstreamZoneName, upstreamZoneServer.Server, + ) } } } @@ -160,8 +180,6 @@ func (r *nginxScraper) recordVtsConnectionStats(now pcommon.Timestamp, vtsStats func (r *nginxScraper) recordTimingStats(now pcommon.Timestamp, vtsStats *NginxVtsStatus) { - // r.mb.RecordNginxLoadTimestampDataPoint(now, vtsStats.LoadMsec) - for upstreamZones, v := range vtsStats.UpstreamZones { for _, val := range v { pp.Println(val.Server) @@ -173,3 +191,11 @@ func (r *nginxScraper) recordTimingStats(now pcommon.Timestamp, vtsStats *NginxV } } } + +func boolToInt(bitSet bool) int8 { + var bitSetVar int8 + if bitSet { + bitSetVar = 1 + } + return bitSetVar +} diff --git a/receiver/nginxreceiver/vts_stats.go b/receiver/nginxreceiver/vts_stats.go index 0b7dd88d16bf..52eec4f9aa91 100644 --- a/receiver/nginxreceiver/vts_stats.go +++ b/receiver/nginxreceiver/vts_stats.go @@ -85,7 +85,7 @@ type UpstreamServer struct { ResponseMsec int64 `json:"responseMsec"` ResponseMsecs RequestMetrics `json:"responseMsecs"` ResponseBuckets RequestBuckets `json:"responseBuckets"` - Weight int `json:"weight"` + Weight float64 `json:"weight"` MaxFails int `json:"maxFails"` FailTimeout int `json:"failTimeout"` Backup bool `json:"backup"`