diff --git a/README.md b/README.md index 3d4b04da..d86bc671 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ the API was first introduced. | 6 | R20 | | 7 | R25 | | 8 | R27 | +| 9 | R30 | ## Using the Client diff --git a/client/nginx.go b/client/nginx.go index 11cf093a..c6fb9f68 100644 --- a/client/nginx.go +++ b/client/nginx.go @@ -15,7 +15,7 @@ import ( const ( // APIVersion is the default version of NGINX Plus API supported by the client. - APIVersion = 8 + APIVersion = 9 pathNotFoundCode = "PathNotFound" streamContext = true @@ -24,7 +24,7 @@ const ( ) var ( - supportedAPIVersions = versions{4, 5, 6, 7, 8} + supportedAPIVersions = versions{4, 5, 6, 7, 8, 9} // Default values for servers in Upstreams. defaultMaxConns = 0 @@ -132,6 +132,7 @@ type Stats struct { HTTPLimitRequests HTTPLimitRequests HTTPLimitConnections HTTPLimitConnections StreamLimitConnections StreamLimitConnections + Workers []*Workers } // NginxInfo contains general information about NGINX Plus. @@ -494,6 +495,19 @@ type HTTPLimitConnections map[string]LimitConnection // StreamLimitConnections represents limit connections related stats type StreamLimitConnections map[string]LimitConnection +// Workers represents worker connections related stats +type Workers struct { + ID int + ProcessID uint64 `json:"pid"` + HTTP WorkersHTTP `json:"http"` + Connections Connections +} + +// WorkersHTTP represents HTTP worker connections +type WorkersHTTP struct { + HTTPRequests HTTPRequests `json:"requests"` +} + // NewNginxClient creates an NginxClient with the latest supported version. func NewNginxClient(httpClient *http.Client, apiEndpoint string) (*NginxClient, error) { return NewNginxClientWithVersion(httpClient, apiEndpoint, APIVersion) @@ -1186,6 +1200,11 @@ func (client *NginxClient) GetStats() (*Stats, error) { return nil, fmt.Errorf("failed to get stats: %w", err) } + workers, err := client.GetWorkers() + if err != nil { + return nil, fmt.Errorf("failed to get stats: %w", err) + } + return &Stats{ NginxInfo: *info, Caches: *caches, @@ -1204,6 +1223,7 @@ func (client *NginxClient) GetStats() (*Stats, error) { HTTPLimitRequests: *limitReqs, HTTPLimitConnections: *limitConnsHTTP, StreamLimitConnections: *limitConnsStream, + Workers: workers, }, nil } @@ -1639,3 +1659,16 @@ func (client *NginxClient) GetStreamConnectionsLimit() (*StreamLimitConnections, } return &limitConns, nil } + +// GetWorkers returns workers stats. +func (client *NginxClient) GetWorkers() ([]*Workers, error) { + var workers []*Workers + if client.version < 9 { + return workers, nil + } + err := client.get("workers", &workers) + if err != nil { + return nil, fmt.Errorf("failed to get workers: %w", err) + } + return workers, nil +} diff --git a/tests/client_test.go b/tests/client_test.go index dff8383a..27fb84e9 100644 --- a/tests/client_test.go +++ b/tests/client_test.go @@ -627,6 +627,10 @@ func TestStats(t *testing.T) { t.Errorf("Bad connections: %v", stats.Connections) } + if len(stats.Workers) < 1 { + t.Errorf("Bad workers: %v", stats.Workers) + } + if val, ok := stats.Caches[cacheZone]; ok { if val.MaxSize != 104857600 { // 100MiB t.Errorf("Cache max size stats missing: %v", val.Size)