Skip to content

Commit

Permalink
added version 9 of API and new worker metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveromahony committed Aug 10, 2023
1 parent 8460a36 commit aa584ca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
33 changes: 33 additions & 0 deletions client/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type Stats struct {
HTTPLimitRequests HTTPLimitRequests
HTTPLimitConnections HTTPLimitConnections
StreamLimitConnections StreamLimitConnections
Workers Workers
}

// NginxInfo contains general information about NGINX Plus.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -1204,6 +1223,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
HTTPLimitRequests: *limitReqs,
HTTPLimitConnections: *limitConnsHTTP,
StreamLimitConnections: *limitConnsStream,
Workers: *workers,
}, nil
}

Expand Down Expand Up @@ -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
}

0 comments on commit aa584ca

Please sign in to comment.