diff --git a/Makefile b/Makefile index e2fb6c12..d070c53a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -NGINX_PLUS_VERSION=r29 +NGINX_PLUS_VERSION=r30 DOCKER_NETWORK?=test DOCKER_NETWORK_ALIAS=nginx-plus-test DOCKER_NGINX_PLUS?=nginx-plus diff --git a/client/nginx.go b/client/nginx.go index 11cf093a..7276f6c4 100644 --- a/client/nginx.go +++ b/client/nginx.go @@ -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 < 8 { + return &workers, nil + } + err := client.get("workers", &workers) + if err != nil { + return nil, fmt.Errorf("failed to get workers: %w", err) + } + return &workers, nil +}