From bf1c2c9bf931270a1594c1b758dabd6db9d4255c Mon Sep 17 00:00:00 2001 From: Steven Hessing Date: Thu, 23 Sep 2021 11:02:55 -0700 Subject: [PATCH] add metric for max_conns of upstream servers (#201) --- README.md | 4 +++- collector/nginx_plus.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8fb29dd..b70c954 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,7 @@ Name | Type | Description | Labels ----|----|----|----| `nginxplus_upstream_server_state` | Gauge | Current state | `server`, `upstream` | `nginxplus_upstream_server_active` | Gauge | Active connections | `server`, `upstream` | +`nginxplus_upstream_server_limit` | Gauge | Limit for connections which corresponds to the max_conns parameter of the upstream server. Zero value means there is no limit | `server`, `upstream` | `nginxplus_upstream_server_requests` | Counter | Total client requests | `server`, `upstream` | `nginxplus_upstream_server_responses` | Counter | Total responses sent to clients | `code` (the response status code. The values are: `1xx`, `2xx`, `3xx`, `4xx` and `5xx`), `server`, `upstream` | `nginxplus_upstream_server_sent` | Counter | Bytes sent to this server | `server`, `upstream` | @@ -195,8 +196,9 @@ Name | Type | Description | Labels ----|----|----|----| `nginxplus_stream_upstream_server_state` | Gauge | Current state | `server`, `upstream` | `nginxplus_stream_upstream_server_active` | Gauge | Active connections | `server` , `upstream` | +`nginxplus_stream_upstream_server_limit` | Gauge | Limit for connections which corresponds to the max_conns parameter of the upstream server. Zero value means there is no limit | `server` , `upstream` | `nginxplus_stream_upstream_server_connections` | Counter | Total number of client connections forwarded to this server | `server`, `upstream` | -`nginxplus_stream_upstream_server_connect_time` | Gauge | Average time to connect to the upstream server | `server`, `upstream` +`nginxplus_stream_upstream_server_connect_time` | Gauge | Average time to connect to the upstream server | `server`, `upstream` `nginxplus_stream_upstream_server_first_byte_time` | Gauge | Average time to receive the first byte of data | `server`, `upstream` | `nginxplus_stream_upstream_server_response_time` | Gauge | Average time to receive the last byte of data | `server`, `upstream` | `nginxplus_stream_upstream_server_sent` | Counter | Bytes sent to this server | `server`, `upstream` | diff --git a/collector/nginx_plus.go b/collector/nginx_plus.go index fcbe884..75c7cb1 100644 --- a/collector/nginx_plus.go +++ b/collector/nginx_plus.go @@ -273,6 +273,7 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string upstreamServerMetrics: map[string]*prometheus.Desc{ "state": newUpstreamServerMetric(namespace, "state", "Current state", upstreamServerVariableLabelNames, constLabels), "active": newUpstreamServerMetric(namespace, "active", "Active connections", upstreamServerVariableLabelNames, constLabels), + "limit": newUpstreamServerMetric(namespace, "limit", "Limit for connections which corresponds to the max_conns parameter of the upstream server. Zero value means there is no limit", upstreamServerVariableLabelNames, constLabels), "requests": newUpstreamServerMetric(namespace, "requests", "Total client requests", upstreamServerVariableLabelNames, constLabels), "responses_1xx": newUpstreamServerMetric(namespace, "responses", "Total responses sent to clients", upstreamServerVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "1xx"})), "responses_2xx": newUpstreamServerMetric(namespace, "responses", "Total responses sent to clients", upstreamServerVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "2xx"})), @@ -292,6 +293,7 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string streamUpstreamServerMetrics: map[string]*prometheus.Desc{ "state": newStreamUpstreamServerMetric(namespace, "state", "Current state", streamUpstreamServerVariableLabelNames, constLabels), "active": newStreamUpstreamServerMetric(namespace, "active", "Active connections", streamUpstreamServerVariableLabelNames, constLabels), + "limit": newStreamUpstreamServerMetric(namespace, "limit", "Limit for connections which corresponds to the max_conns parameter of the upstream server. Zero value means there is no limit", streamUpstreamServerVariableLabelNames, constLabels), "sent": newStreamUpstreamServerMetric(namespace, "sent", "Bytes sent to this server", streamUpstreamServerVariableLabelNames, constLabels), "received": newStreamUpstreamServerMetric(namespace, "received", "Bytes received from this server", streamUpstreamServerVariableLabelNames, constLabels), "fails": newStreamUpstreamServerMetric(namespace, "fails", "Number of unsuccessful attempts to communicate with the server", streamUpstreamServerVariableLabelNames, constLabels), @@ -511,6 +513,8 @@ func (c *NginxPlusCollector) Collect(ch chan<- prometheus.Metric) { prometheus.GaugeValue, upstreamServerStates[peer.State], labelValues...) ch <- prometheus.MustNewConstMetric(c.upstreamServerMetrics["active"], prometheus.GaugeValue, float64(peer.Active), labelValues...) + ch <- prometheus.MustNewConstMetric(c.upstreamServerMetrics["limit"], + prometheus.GaugeValue, float64(peer.MaxConns), labelValues...) ch <- prometheus.MustNewConstMetric(c.upstreamServerMetrics["requests"], prometheus.CounterValue, float64(peer.Requests), labelValues...) ch <- prometheus.MustNewConstMetric(c.upstreamServerMetrics["responses_1xx"], @@ -582,6 +586,8 @@ func (c *NginxPlusCollector) Collect(ch chan<- prometheus.Metric) { prometheus.GaugeValue, upstreamServerStates[peer.State], labelValues...) ch <- prometheus.MustNewConstMetric(c.streamUpstreamServerMetrics["active"], prometheus.GaugeValue, float64(peer.Active), labelValues...) + ch <- prometheus.MustNewConstMetric(c.streamUpstreamServerMetrics["limit"], + prometheus.GaugeValue, float64(peer.MaxConns), labelValues...) ch <- prometheus.MustNewConstMetric(c.streamUpstreamServerMetrics["connections"], prometheus.CounterValue, float64(peer.Connections), labelValues...) ch <- prometheus.MustNewConstMetric(c.streamUpstreamServerMetrics["connect_time"],