Skip to content

Commit 01a672d

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

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,19 @@ type HTTPLimitConnections map[string]LimitConnection
494494
// StreamLimitConnections represents limit connections related stats
495495
type StreamLimitConnections map[string]LimitConnection
496496

497+
// Workers represents worker connections related stats
498+
type Workers struct {
499+
ID int
500+
ProcessID uint64 `json:"pid"`
501+
HTTP WorkersHTTP `json:"http"`
502+
Connections Connections
503+
}
504+
505+
// WorkersHTTP represents HTTP worker connections
506+
type WorkersHTTP struct {
507+
HTTPRequests HTTPRequests `json:"requests"`
508+
}
509+
497510
// NewNginxClient creates an NginxClient with the latest supported version.
498511
func NewNginxClient(httpClient *http.Client, apiEndpoint string) (*NginxClient, error) {
499512
return NewNginxClientWithVersion(httpClient, apiEndpoint, APIVersion)
@@ -1186,6 +1199,11 @@ func (client *NginxClient) GetStats() (*Stats, error) {
11861199
return nil, fmt.Errorf("failed to get stats: %w", err)
11871200
}
11881201

1202+
workers, err := client.GetWorkers()
1203+
if err != nil {
1204+
return nil, fmt.Errorf("failed to get stats: %w", err)
1205+
}
1206+
11891207
return &Stats{
11901208
NginxInfo: *info,
11911209
Caches: *caches,
@@ -1204,6 +1222,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
12041222
HTTPLimitRequests: *limitReqs,
12051223
HTTPLimitConnections: *limitConnsHTTP,
12061224
StreamLimitConnections: *limitConnsStream,
1225+
Workers: *workers,
12071226
}, nil
12081227
}
12091228

@@ -1639,3 +1658,16 @@ func (client *NginxClient) GetStreamConnectionsLimit() (*StreamLimitConnections,
16391658
}
16401659
return &limitConns, nil
16411660
}
1661+
1662+
// GetWorkers returns workers stats.
1663+
func (client *NginxClient) GetWorkers() (*Workers, error) {
1664+
var workers Workers
1665+
if client.version < 8 {
1666+
return &workers, nil
1667+
}
1668+
err := client.get("workers", &workers)
1669+
if err != nil {
1670+
return nil, fmt.Errorf("failed to get workers: %w", err)
1671+
}
1672+
return &workers, nil
1673+
}

0 commit comments

Comments
 (0)