Skip to content

Commit aa584ca

Browse files
committed
added version 9 of API and new worker metrics
1 parent 8460a36 commit aa584ca

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NGINX_PLUS_VERSION=r29
1+
NGINX_PLUS_VERSION=r30
22
DOCKER_NETWORK?=test
33
DOCKER_NETWORK_ALIAS=nginx-plus-test
44
DOCKER_NGINX_PLUS?=nginx-plus

client/nginx.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
495496
type 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.
498512
func 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 < 8 {
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

Comments
 (0)