@@ -10,7 +10,7 @@ import (
1010)
1111
1212// APIVersion is a version of NGINX Plus API.
13- const APIVersion = 4
13+ const APIVersion = 5
1414
1515const pathNotFoundCode = "PathNotFound"
1616
@@ -101,6 +101,8 @@ type Stats struct {
101101 StreamServerZones StreamServerZones
102102 StreamUpstreams StreamUpstreams
103103 StreamZoneSync * StreamZoneSync
104+ LocationZones LocationZones
105+ Resolvers Resolvers
104106}
105107
106108// NginxInfo contains general information about NGINX Plus.
@@ -288,6 +290,46 @@ type HealthChecks struct {
288290 LastPassed bool `json:"last_passed"`
289291}
290292
293+ // LocationZones represents location_zones related stats
294+ type LocationZones map [string ]LocationZone
295+
296+ // Resolvers represents resolvers related stats
297+ type Resolvers map [string ]Resolver
298+
299+ // LocationZone represents location_zones related stats
300+ type LocationZone struct {
301+ Requests int64
302+ Responses Responses
303+ Discarded int64
304+ Received int64
305+ Sent int64
306+ }
307+
308+ // Resolver represents resolvers related stats
309+ type Resolver struct {
310+ Requests ResolverRequests `json:"requests"`
311+ Responses ResolverResponses `json:"responses"`
312+ }
313+
314+ // ResolverRequests represents resolver requests
315+ type ResolverRequests struct {
316+ Name int64
317+ Srv int64
318+ Addr int64
319+ }
320+
321+ // ResolverResponses represents resolver responses
322+ type ResolverResponses struct {
323+ Noerror int64
324+ Formerr int64
325+ Servfail int64
326+ Nxdomain int64
327+ Notimp int64
328+ Refused int64
329+ Timedout int64
330+ Unknown int64
331+ }
332+
291333// NewNginxClient creates an NginxClient.
292334func NewNginxClient (httpClient * http.Client , apiEndpoint string ) (* NginxClient , error ) {
293335 versions , err := getAPIVersions (httpClient , apiEndpoint )
@@ -767,6 +809,16 @@ func (client *NginxClient) GetStats() (*Stats, error) {
767809 return nil , fmt .Errorf ("failed to get stats: %v" , err )
768810 }
769811
812+ locationZones , err := client .getLocationZones ()
813+ if err != nil {
814+ return nil , fmt .Errorf ("failed to get stats: %v" , err )
815+ }
816+
817+ resolvers , err := client .getResolvers ()
818+ if err != nil {
819+ return nil , fmt .Errorf ("failed to get stats: %v" , err )
820+ }
821+
770822 return & Stats {
771823 NginxInfo : * info ,
772824 Connections : * cons ,
@@ -777,6 +829,8 @@ func (client *NginxClient) GetStats() (*Stats, error) {
777829 Upstreams : * upstreams ,
778830 StreamUpstreams : * streamUpstreams ,
779831 StreamZoneSync : streamZoneSync ,
832+ LocationZones : * locationZones ,
833+ Resolvers : * resolvers ,
780834 }, nil
781835}
782836
@@ -877,6 +931,26 @@ func (client *NginxClient) getStreamZoneSync() (*StreamZoneSync, error) {
877931 return & streamZoneSync , err
878932}
879933
934+ func (client * NginxClient ) getLocationZones () (* LocationZones , error ) {
935+ var locationZones LocationZones
936+ err := client .get ("http/location_zones" , & locationZones )
937+ if err != nil {
938+ return nil , fmt .Errorf ("failed to get location zones: %v" , err )
939+ }
940+
941+ return & locationZones , err
942+ }
943+
944+ func (client * NginxClient ) getResolvers () (* Resolvers , error ) {
945+ var resolvers Resolvers
946+ err := client .get ("resolvers" , & resolvers )
947+ if err != nil {
948+ return nil , fmt .Errorf ("failed to get resolvers: %v" , err )
949+ }
950+
951+ return & resolvers , err
952+ }
953+
880954// KeyValPairs are the key-value pairs stored in a zone.
881955type KeyValPairs map [string ]string
882956
0 commit comments