Skip to content

Commit bf392f0

Browse files
authored
Add metrics from NGINX Plus API version 6 (#281)
1 parent f452ae5 commit bf392f0

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,30 @@ Name | Type | Description | Labels
245245
`nginxplus_resolver_timedout` | Counter | Total number of timed out request | `resolver` |
246246
`nginxplus_resolver_unknown` | Counter | Total requests completed with an unknown error | `resolver`|
247247
248+
#### [HTTP Requests Rate Limiting](https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_http_limit_req_zone)
249+
Name | Type | Description | Labels
250+
----|----|----|----|
251+
`nginxplus_limit_request_passed` | Counter | Total number of requests that were neither limited nor accounted as limited | `zone` |
252+
`nginxplus_limit_request_rejected` | Counter | Total number of requests that were that were rejected | `zone` |
253+
`nginxplus_limit_request_delayed` | Counter | Total number of requests that were delayed | `zone` |
254+
`nginxplus_limit_request_rejected_dry_run` | Counter | Total number of requests accounted as rejected in the dry run mode | `zone` |
255+
`nginxplus_limit_request_delayed_dry_run` | Counter | Total number of requests accounted as delayed in the dry run mode | `zone` |
256+
257+
#### [HTTP Connections Limiting](https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_http_limit_conn_zone)
258+
Name | Type | Description | Labels
259+
----|----|----|----|
260+
`nginxplus_limit_connection_passed` | Counter | Total number of connections that were neither limited nor accounted as limited | `zone` |
261+
`nginxplus_limit_connection_rejected` | Counter | Total number of connections that were rejected | `zone` |
262+
`nginxplus_limit_connection_rejected_dry_run` | Counter | Total number of connections accounted as rejected in the dry run mode | `zone` |
263+
264+
265+
#### [Stream Connections Limiting](https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_stream_limit_conn_zone)
266+
Name | Type | Description | Labels
267+
----|----|----|----|
268+
`nginxplus_stream_limit_connection_passed` | Counter | Total number of connections that were neither limited nor accounted as limited | `zone` |
269+
`nginxplus_stream_limit_connection_rejected` | Counter | Total number of connections that were rejected | `zone` |
270+
`nginxplus_stream_limit_connection_rejected_dry_run` | Counter | Total number of connections accounted as rejected in the dry run mode | `zone` |
271+
248272
Connect to the `/metrics` page of the running exporter to see the complete list of metrics along with their descriptions. Note: to see server zones related metrics you must configure [status zones](https://nginx.org/en/docs/http/ngx_http_status_module.html#status_zone) and to see upstream related metrics you must configure upstreams with a [shared memory zone](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#zone).
249273
250274
## Troubleshooting

collector/nginx_plus.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ type NginxPlusCollector struct {
3838
streamUpstreamServerMetrics map[string]*prometheus.Desc
3939
locationZoneMetrics map[string]*prometheus.Desc
4040
resolverMetrics map[string]*prometheus.Desc
41+
limitRequestMetrics map[string]*prometheus.Desc
42+
limitConnectionMetrics map[string]*prometheus.Desc
43+
streamLimitConnectionMetrics map[string]*prometheus.Desc
4144
upMetric prometheus.Gauge
4245
mutex sync.Mutex
4346
variableLabelNames VariableLabelNames
@@ -340,6 +343,23 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string
340343
"timedout": newResolverMetric(namespace, "timedout", "Total number of timed out requests", constLabels),
341344
"unknown": newResolverMetric(namespace, "unknown", "Total requests completed with an unknown error", constLabels),
342345
},
346+
limitRequestMetrics: map[string]*prometheus.Desc{
347+
"passed": newLimitRequestMetric(namespace, "passed", "Total number of requests that were neither limited nor accounted as limited", constLabels),
348+
"delayed": newLimitRequestMetric(namespace, "delayed", "Total number of requests that were delayed", constLabels),
349+
"rejected": newLimitRequestMetric(namespace, "rejected", "Total number of requests that were that were rejected", constLabels),
350+
"delayed_dry_run": newLimitRequestMetric(namespace, "delayed_dry_run", "Total number of requests accounted as delayed in the dry run mode", constLabels),
351+
"rejected_dry_run": newLimitRequestMetric(namespace, "rejected_dry_run", "Total number of requests accounted as rejected in the dry run mode", constLabels),
352+
},
353+
limitConnectionMetrics: map[string]*prometheus.Desc{
354+
"passed": newLimitConnectionMetric(namespace, "passed", "Total number of connections that were neither limited nor accounted as limited", constLabels),
355+
"rejected": newLimitConnectionMetric(namespace, "rejected", "Total number of connections that were rejected", constLabels),
356+
"rejected_dry_run": newLimitConnectionMetric(namespace, "rejected_dry_run", "Total number of connections accounted as rejected in the dry run mode", constLabels),
357+
},
358+
streamLimitConnectionMetrics: map[string]*prometheus.Desc{
359+
"passed": newStreamLimitConnectionMetric(namespace, "passed", "Total number of connections that were neither limited nor accounted as limited", constLabels),
360+
"rejected": newStreamLimitConnectionMetric(namespace, "rejected", "Total number of connections that were rejected", constLabels),
361+
"rejected_dry_run": newStreamLimitConnectionMetric(namespace, "rejected_dry_run", "Total number of connections accounted as rejected in the dry run mode", constLabels),
362+
},
343363
upMetric: newUpMetric(namespace, constLabels),
344364
}
345365
}
@@ -379,6 +399,15 @@ func (c *NginxPlusCollector) Describe(ch chan<- *prometheus.Desc) {
379399
for _, m := range c.resolverMetrics {
380400
ch <- m
381401
}
402+
for _, m := range c.limitRequestMetrics {
403+
ch <- m
404+
}
405+
for _, m := range c.limitConnectionMetrics {
406+
ch <- m
407+
}
408+
for _, m := range c.streamLimitConnectionMetrics {
409+
ch <- m
410+
}
382411
}
383412

384413
// Collect fetches metrics from NGINX Plus and sends them to the provided channel.
@@ -683,6 +712,26 @@ func (c *NginxPlusCollector) Collect(ch chan<- prometheus.Metric) {
683712
ch <- prometheus.MustNewConstMetric(c.resolverMetrics["unknown"],
684713
prometheus.CounterValue, float64(zone.Responses.Unknown), name)
685714
}
715+
716+
for name, zone := range stats.HTTPLimitRequests {
717+
ch <- prometheus.MustNewConstMetric(c.limitRequestMetrics["passed"], prometheus.CounterValue, float64(zone.Passed), name)
718+
ch <- prometheus.MustNewConstMetric(c.limitRequestMetrics["rejected"], prometheus.CounterValue, float64(zone.Rejected), name)
719+
ch <- prometheus.MustNewConstMetric(c.limitRequestMetrics["delayed"], prometheus.CounterValue, float64(zone.Delayed), name)
720+
ch <- prometheus.MustNewConstMetric(c.limitRequestMetrics["rejected_dry_run"], prometheus.CounterValue, float64(zone.RejectedDryRun), name)
721+
ch <- prometheus.MustNewConstMetric(c.limitRequestMetrics["delayed_dry_run"], prometheus.CounterValue, float64(zone.DelayedDryRun), name)
722+
}
723+
724+
for name, zone := range stats.HTTPLimitConnections {
725+
ch <- prometheus.MustNewConstMetric(c.limitConnectionMetrics["passed"], prometheus.CounterValue, float64(zone.Passed), name)
726+
ch <- prometheus.MustNewConstMetric(c.limitConnectionMetrics["rejected"], prometheus.CounterValue, float64(zone.Rejected), name)
727+
ch <- prometheus.MustNewConstMetric(c.limitConnectionMetrics["rejected_dry_run"], prometheus.CounterValue, float64(zone.RejectedDryRun), name)
728+
}
729+
730+
for name, zone := range stats.StreamLimitConnections {
731+
ch <- prometheus.MustNewConstMetric(c.streamLimitConnectionMetrics["passed"], prometheus.CounterValue, float64(zone.Passed), name)
732+
ch <- prometheus.MustNewConstMetric(c.streamLimitConnectionMetrics["rejected"], prometheus.CounterValue, float64(zone.Rejected), name)
733+
ch <- prometheus.MustNewConstMetric(c.streamLimitConnectionMetrics["rejected_dry_run"], prometheus.CounterValue, float64(zone.RejectedDryRun), name)
734+
}
686735
}
687736

688737
var upstreamServerStates = map[string]float64{
@@ -741,3 +790,15 @@ func newLocationZoneMetric(namespace string, metricName string, docString string
741790
func newResolverMetric(namespace string, metricName string, docString string, constLabels prometheus.Labels) *prometheus.Desc {
742791
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "resolver", metricName), docString, []string{"resolver"}, constLabels)
743792
}
793+
794+
func newLimitRequestMetric(namespace string, metricName string, docString string, constLabels prometheus.Labels) *prometheus.Desc {
795+
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "limit_request", metricName), docString, []string{"zone"}, constLabels)
796+
}
797+
798+
func newLimitConnectionMetric(namespace string, metricName string, docString string, constLabels prometheus.Labels) *prometheus.Desc {
799+
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "limit_connection", metricName), docString, []string{"zone"}, constLabels)
800+
}
801+
802+
func newStreamLimitConnectionMetric(namespace string, metricName string, docString string, constLabels prometheus.Labels) *prometheus.Desc {
803+
return prometheus.NewDesc(prometheus.BuildFQName(namespace, "stream_limit_connection", metricName), docString, []string{"zone"}, constLabels)
804+
}

0 commit comments

Comments
 (0)