@@ -10,7 +10,7 @@ import (
10
10
)
11
11
12
12
// APIVersion is a version of NGINX Plus API.
13
- const APIVersion = 4
13
+ const APIVersion = 5
14
14
15
15
const pathNotFoundCode = "PathNotFound"
16
16
@@ -101,6 +101,8 @@ type Stats struct {
101
101
StreamServerZones StreamServerZones
102
102
StreamUpstreams StreamUpstreams
103
103
StreamZoneSync * StreamZoneSync
104
+ LocationZones LocationZones
105
+ Resolvers Resolvers
104
106
}
105
107
106
108
// NginxInfo contains general information about NGINX Plus.
@@ -288,6 +290,46 @@ type HealthChecks struct {
288
290
LastPassed bool `json:"last_passed"`
289
291
}
290
292
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
+
291
333
// NewNginxClient creates an NginxClient.
292
334
func NewNginxClient (httpClient * http.Client , apiEndpoint string ) (* NginxClient , error ) {
293
335
versions , err := getAPIVersions (httpClient , apiEndpoint )
@@ -767,6 +809,16 @@ func (client *NginxClient) GetStats() (*Stats, error) {
767
809
return nil , fmt .Errorf ("failed to get stats: %v" , err )
768
810
}
769
811
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
+
770
822
return & Stats {
771
823
NginxInfo : * info ,
772
824
Connections : * cons ,
@@ -777,6 +829,8 @@ func (client *NginxClient) GetStats() (*Stats, error) {
777
829
Upstreams : * upstreams ,
778
830
StreamUpstreams : * streamUpstreams ,
779
831
StreamZoneSync : streamZoneSync ,
832
+ LocationZones : * locationZones ,
833
+ Resolvers : * resolvers ,
780
834
}, nil
781
835
}
782
836
@@ -877,6 +931,26 @@ func (client *NginxClient) getStreamZoneSync() (*StreamZoneSync, error) {
877
931
return & streamZoneSync , err
878
932
}
879
933
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
+
880
954
// KeyValPairs are the key-value pairs stored in a zone.
881
955
type KeyValPairs map [string ]string
882
956
0 commit comments