@@ -15,7 +15,7 @@ import (
1515
1616const (
1717 // APIVersion is the default version of NGINX Plus API supported by the client.
18- APIVersion = 8
18+ APIVersion = 9
1919
2020 pathNotFoundCode = "PathNotFound"
2121 streamContext = true
@@ -24,7 +24,7 @@ const (
2424)
2525
2626var (
27- supportedAPIVersions = versions {4 , 5 , 6 , 7 , 8 }
27+ supportedAPIVersions = versions {4 , 5 , 6 , 7 , 8 , 9 }
2828
2929 // Default values for servers in Upstreams.
3030 defaultMaxConns = 0
@@ -132,6 +132,7 @@ type Stats struct {
132132 HTTPLimitRequests HTTPLimitRequests
133133 HTTPLimitConnections HTTPLimitConnections
134134 StreamLimitConnections StreamLimitConnections
135+ Workers []* Workers
135136}
136137
137138// NginxInfo contains general information about NGINX Plus.
@@ -494,6 +495,19 @@ type HTTPLimitConnections map[string]LimitConnection
494495// StreamLimitConnections represents limit connections related stats
495496type StreamLimitConnections map [string ]LimitConnection
496497
498+ // Workers represents worker connections related stats
499+ type Workers struct {
500+ ID int
501+ ProcessID uint64 `json:"pid"`
502+ HTTP WorkersHTTP `json:"http"`
503+ Connections Connections
504+ }
505+
506+ // WorkersHTTP represents HTTP worker connections
507+ type WorkersHTTP struct {
508+ HTTPRequests HTTPRequests `json:"requests"`
509+ }
510+
497511// NewNginxClient creates an NginxClient with the latest supported version.
498512func NewNginxClient (httpClient * http.Client , apiEndpoint string ) (* NginxClient , error ) {
499513 return NewNginxClientWithVersion (httpClient , apiEndpoint , APIVersion )
@@ -1186,6 +1200,11 @@ func (client *NginxClient) GetStats() (*Stats, error) {
11861200 return nil , fmt .Errorf ("failed to get stats: %w" , err )
11871201 }
11881202
1203+ workers , err := client .GetWorkers ()
1204+ if err != nil {
1205+ return nil , fmt .Errorf ("failed to get stats: %w" , err )
1206+ }
1207+
11891208 return & Stats {
11901209 NginxInfo : * info ,
11911210 Caches : * caches ,
@@ -1204,6 +1223,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
12041223 HTTPLimitRequests : * limitReqs ,
12051224 HTTPLimitConnections : * limitConnsHTTP ,
12061225 StreamLimitConnections : * limitConnsStream ,
1226+ Workers : workers ,
12071227 }, nil
12081228}
12091229
@@ -1639,3 +1659,16 @@ func (client *NginxClient) GetStreamConnectionsLimit() (*StreamLimitConnections,
16391659 }
16401660 return & limitConns , nil
16411661}
1662+
1663+ // GetWorkers returns workers stats.
1664+ func (client * NginxClient ) GetWorkers () ([]* Workers , error ) {
1665+ var workers []* Workers
1666+ if client .version < 9 {
1667+ return workers , nil
1668+ }
1669+ err := client .get ("workers" , & workers )
1670+ if err != nil {
1671+ return nil , fmt .Errorf ("failed to get workers: %w" , err )
1672+ }
1673+ return workers , nil
1674+ }
0 commit comments