@@ -19,6 +19,8 @@ type NginxPlusCollector struct {
1919 streamUpstreamMetrics map [string ]* prometheus.Desc
2020 streamUpstreamServerMetrics map [string ]* prometheus.Desc
2121 streamZoneSyncMetrics map [string ]* prometheus.Desc
22+ locationZoneMetrics map [string ]* prometheus.Desc
23+ resolverMetrics map [string ]* prometheus.Desc
2224 upMetric prometheus.Gauge
2325 mutex sync.Mutex
2426}
@@ -110,6 +112,30 @@ func NewNginxPlusCollector(nginxClient *plusclient.NginxClient, namespace string
110112 "records_pending" : newStreamZoneSyncZoneMetric (namespace , "records_pending" , "The number of records that need to be sent to the cluster" ),
111113 "records_total" : newStreamZoneSyncZoneMetric (namespace , "records_total" , "The total number of records stored in the shared memory zone" ),
112114 },
115+ locationZoneMetrics : map [string ]* prometheus.Desc {
116+ "requests" : newLocationZoneMetric (namespace , "requests" , "Total client requests" , nil ),
117+ "responses_1xx" : newLocationZoneMetric (namespace , "responses" , "Total responses sent to clients" , prometheus.Labels {"code" : "1xx" }),
118+ "responses_2xx" : newLocationZoneMetric (namespace , "responses" , "Total responses sent to clients" , prometheus.Labels {"code" : "2xx" }),
119+ "responses_3xx" : newLocationZoneMetric (namespace , "responses" , "Total responses sent to clients" , prometheus.Labels {"code" : "3xx" }),
120+ "responses_4xx" : newLocationZoneMetric (namespace , "responses" , "Total responses sent to clients" , prometheus.Labels {"code" : "4xx" }),
121+ "responses_5xx" : newLocationZoneMetric (namespace , "responses" , "Total responses sent to clients" , prometheus.Labels {"code" : "5xx" }),
122+ "discarded" : newLocationZoneMetric (namespace , "discarded" , "Requests completed without sending a response" , nil ),
123+ "received" : newLocationZoneMetric (namespace , "received" , "Bytes received from clients" , nil ),
124+ "sent" : newLocationZoneMetric (namespace , "sent" , "Bytes sent to clients" , nil ),
125+ },
126+ resolverMetrics : map [string ]* prometheus.Desc {
127+ "name" : newResolverMetric (namespace , "name" , "Total requests to resolve names to addresses" ),
128+ "srv" : newResolverMetric (namespace , "srv" , "Total requests to resolve SRV records" ),
129+ "addr" : newResolverMetric (namespace , "addr" , "Total requests to resolve addresses to names" ),
130+ "noerror" : newResolverMetric (namespace , "noerror" , "Total number of successful responses" ),
131+ "formerr" : newResolverMetric (namespace , "formerr" , "Total number of FORMERR responses" ),
132+ "servfail" : newResolverMetric (namespace , "servfail" , "Total number of SERVFAIL responses" ),
133+ "nxdomain" : newResolverMetric (namespace , "nxdomain" , "Total number of NXDOMAIN responses" ),
134+ "notimp" : newResolverMetric (namespace , "notimp" , "Total number of NOTIMP responses" ),
135+ "refused" : newResolverMetric (namespace , "refused" , "Total number of REFUSED responses" ),
136+ "timedout" : newResolverMetric (namespace , "timedout" , "Total number of timed out requests" ),
137+ "unknown" : newResolverMetric (namespace , "unknown" , "Total requests completed with an unknown error" ),
138+ },
113139 upMetric : newUpMetric (namespace ),
114140 }
115141}
@@ -143,6 +169,12 @@ func (c *NginxPlusCollector) Describe(ch chan<- *prometheus.Desc) {
143169 for _ , m := range c .streamZoneSyncMetrics {
144170 ch <- m
145171 }
172+ for _ , m := range c .locationZoneMetrics {
173+ ch <- m
174+ }
175+ for _ , m := range c .resolverMetrics {
176+ ch <- m
177+ }
146178}
147179
148180// Collect fetches metrics from NGINX Plus and sends them to the provided channel.
@@ -322,6 +354,52 @@ func (c *NginxPlusCollector) Collect(ch chan<- prometheus.Metric) {
322354 ch <- prometheus .MustNewConstMetric (c .streamZoneSyncMetrics ["nodes_online" ],
323355 prometheus .GaugeValue , float64 (stats .StreamZoneSync .Status .NodesOnline ))
324356 }
357+
358+ for name , zone := range stats .LocationZones {
359+ ch <- prometheus .MustNewConstMetric (c .locationZoneMetrics ["requests" ],
360+ prometheus .CounterValue , float64 (zone .Requests ), name )
361+ ch <- prometheus .MustNewConstMetric (c .locationZoneMetrics ["responses_1xx" ],
362+ prometheus .CounterValue , float64 (zone .Responses .Responses1xx ), name )
363+ ch <- prometheus .MustNewConstMetric (c .locationZoneMetrics ["responses_2xx" ],
364+ prometheus .CounterValue , float64 (zone .Responses .Responses2xx ), name )
365+ ch <- prometheus .MustNewConstMetric (c .locationZoneMetrics ["responses_3xx" ],
366+ prometheus .CounterValue , float64 (zone .Responses .Responses3xx ), name )
367+ ch <- prometheus .MustNewConstMetric (c .locationZoneMetrics ["responses_4xx" ],
368+ prometheus .CounterValue , float64 (zone .Responses .Responses4xx ), name )
369+ ch <- prometheus .MustNewConstMetric (c .locationZoneMetrics ["responses_5xx" ],
370+ prometheus .CounterValue , float64 (zone .Responses .Responses5xx ), name )
371+ ch <- prometheus .MustNewConstMetric (c .locationZoneMetrics ["discarded" ],
372+ prometheus .CounterValue , float64 (zone .Discarded ), name )
373+ ch <- prometheus .MustNewConstMetric (c .locationZoneMetrics ["received" ],
374+ prometheus .CounterValue , float64 (zone .Received ), name )
375+ ch <- prometheus .MustNewConstMetric (c .locationZoneMetrics ["sent" ],
376+ prometheus .CounterValue , float64 (zone .Sent ), name )
377+ }
378+
379+ for name , zone := range stats .Resolvers {
380+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["name" ],
381+ prometheus .CounterValue , float64 (zone .Requests .Name ), name )
382+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["srv" ],
383+ prometheus .CounterValue , float64 (zone .Requests .Srv ), name )
384+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["addr" ],
385+ prometheus .CounterValue , float64 (zone .Requests .Addr ), name )
386+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["noerror" ],
387+ prometheus .CounterValue , float64 (zone .Responses .Noerror ), name )
388+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["formerr" ],
389+ prometheus .CounterValue , float64 (zone .Responses .Formerr ), name )
390+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["servfail" ],
391+ prometheus .CounterValue , float64 (zone .Responses .Servfail ), name )
392+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["nxdomain" ],
393+ prometheus .CounterValue , float64 (zone .Responses .Nxdomain ), name )
394+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["notimp" ],
395+ prometheus .CounterValue , float64 (zone .Responses .Notimp ), name )
396+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["refused" ],
397+ prometheus .CounterValue , float64 (zone .Responses .Refused ), name )
398+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["timedout" ],
399+ prometheus .CounterValue , float64 (zone .Responses .Timedout ), name )
400+ ch <- prometheus .MustNewConstMetric (c .resolverMetrics ["unknown" ],
401+ prometheus .CounterValue , float64 (zone .Responses .Unknown ), name )
402+ }
325403}
326404
327405var upstreamServerStates = map [string ]float64 {
@@ -364,3 +442,11 @@ func newStreamZoneSyncMetric(namespace string, metricName string, docString stri
364442func newStreamZoneSyncZoneMetric (namespace string , metricName string , docString string ) * prometheus.Desc {
365443 return prometheus .NewDesc (prometheus .BuildFQName (namespace , "stream_zone_sync_zone" , metricName ), docString , []string {"zone" }, nil )
366444}
445+
446+ func newLocationZoneMetric (namespace string , metricName string , docString string , constLabels prometheus.Labels ) * prometheus.Desc {
447+ return prometheus .NewDesc (prometheus .BuildFQName (namespace , "location_zone" , metricName ), docString , []string {"location_zone" }, constLabels )
448+ }
449+
450+ func newResolverMetric (namespace string , metricName string , docString string ) * prometheus.Desc {
451+ return prometheus .NewDesc (prometheus .BuildFQName (namespace , "resolver" , metricName ), docString , []string {"resolver" }, nil )
452+ }
0 commit comments