Skip to content

Commit bf1c2c9

Browse files
author
Steven Hessing
authored
add metric for max_conns of upstream servers (#201)
1 parent dfebae8 commit bf1c2c9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ Name | Type | Description | Labels
173173
----|----|----|----|
174174
`nginxplus_upstream_server_state` | Gauge | Current state | `server`, `upstream` |
175175
`nginxplus_upstream_server_active` | Gauge | Active connections | `server`, `upstream` |
176+
`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` |
176177
`nginxplus_upstream_server_requests` | Counter | Total client requests | `server`, `upstream` |
177178
`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` |
178179
`nginxplus_upstream_server_sent` | Counter | Bytes sent to this server | `server`, `upstream` |
@@ -195,8 +196,9 @@ Name | Type | Description | Labels
195196
----|----|----|----|
196197
`nginxplus_stream_upstream_server_state` | Gauge | Current state | `server`, `upstream` |
197198
`nginxplus_stream_upstream_server_active` | Gauge | Active connections | `server` , `upstream` |
199+
`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` |
198200
`nginxplus_stream_upstream_server_connections` | Counter | Total number of client connections forwarded to this server | `server`, `upstream` |
199-
`nginxplus_stream_upstream_server_connect_time` | Gauge | Average time to connect to the upstream server | `server`, `upstream`
201+
`nginxplus_stream_upstream_server_connect_time` | Gauge | Average time to connect to the upstream server | `server`, `upstream`
200202
`nginxplus_stream_upstream_server_first_byte_time` | Gauge | Average time to receive the first byte of data | `server`, `upstream` |
201203
`nginxplus_stream_upstream_server_response_time` | Gauge | Average time to receive the last byte of data | `server`, `upstream` |
202204
`nginxplus_stream_upstream_server_sent` | Counter | Bytes sent to this server | `server`, `upstream` |

collector/nginx_plus.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string
273273
upstreamServerMetrics: map[string]*prometheus.Desc{
274274
"state": newUpstreamServerMetric(namespace, "state", "Current state", upstreamServerVariableLabelNames, constLabels),
275275
"active": newUpstreamServerMetric(namespace, "active", "Active connections", upstreamServerVariableLabelNames, constLabels),
276+
"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),
276277
"requests": newUpstreamServerMetric(namespace, "requests", "Total client requests", upstreamServerVariableLabelNames, constLabels),
277278
"responses_1xx": newUpstreamServerMetric(namespace, "responses", "Total responses sent to clients", upstreamServerVariableLabelNames, MergeLabels(constLabels, prometheus.Labels{"code": "1xx"})),
278279
"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
292293
streamUpstreamServerMetrics: map[string]*prometheus.Desc{
293294
"state": newStreamUpstreamServerMetric(namespace, "state", "Current state", streamUpstreamServerVariableLabelNames, constLabels),
294295
"active": newStreamUpstreamServerMetric(namespace, "active", "Active connections", streamUpstreamServerVariableLabelNames, constLabels),
296+
"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),
295297
"sent": newStreamUpstreamServerMetric(namespace, "sent", "Bytes sent to this server", streamUpstreamServerVariableLabelNames, constLabels),
296298
"received": newStreamUpstreamServerMetric(namespace, "received", "Bytes received from this server", streamUpstreamServerVariableLabelNames, constLabels),
297299
"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) {
511513
prometheus.GaugeValue, upstreamServerStates[peer.State], labelValues...)
512514
ch <- prometheus.MustNewConstMetric(c.upstreamServerMetrics["active"],
513515
prometheus.GaugeValue, float64(peer.Active), labelValues...)
516+
ch <- prometheus.MustNewConstMetric(c.upstreamServerMetrics["limit"],
517+
prometheus.GaugeValue, float64(peer.MaxConns), labelValues...)
514518
ch <- prometheus.MustNewConstMetric(c.upstreamServerMetrics["requests"],
515519
prometheus.CounterValue, float64(peer.Requests), labelValues...)
516520
ch <- prometheus.MustNewConstMetric(c.upstreamServerMetrics["responses_1xx"],
@@ -582,6 +586,8 @@ func (c *NginxPlusCollector) Collect(ch chan<- prometheus.Metric) {
582586
prometheus.GaugeValue, upstreamServerStates[peer.State], labelValues...)
583587
ch <- prometheus.MustNewConstMetric(c.streamUpstreamServerMetrics["active"],
584588
prometheus.GaugeValue, float64(peer.Active), labelValues...)
589+
ch <- prometheus.MustNewConstMetric(c.streamUpstreamServerMetrics["limit"],
590+
prometheus.GaugeValue, float64(peer.MaxConns), labelValues...)
585591
ch <- prometheus.MustNewConstMetric(c.streamUpstreamServerMetrics["connections"],
586592
prometheus.CounterValue, float64(peer.Connections), labelValues...)
587593
ch <- prometheus.MustNewConstMetric(c.streamUpstreamServerMetrics["connect_time"],

0 commit comments

Comments
 (0)