@@ -15,7 +15,7 @@ import (
15
15
16
16
const (
17
17
// APIVersion is the default version of NGINX Plus API supported by the client.
18
- APIVersion = 8
18
+ APIVersion = 9
19
19
20
20
pathNotFoundCode = "PathNotFound"
21
21
streamContext = true
@@ -24,7 +24,7 @@ const (
24
24
)
25
25
26
26
var (
27
- supportedAPIVersions = versions {4 , 5 , 6 , 7 , 8 }
27
+ supportedAPIVersions = versions {4 , 5 , 6 , 7 , 8 , 9 }
28
28
29
29
// Default values for servers in Upstreams.
30
30
defaultMaxConns = 0
@@ -132,6 +132,7 @@ type Stats struct {
132
132
HTTPLimitRequests HTTPLimitRequests
133
133
HTTPLimitConnections HTTPLimitConnections
134
134
StreamLimitConnections StreamLimitConnections
135
+ Workers []* Workers
135
136
}
136
137
137
138
// NginxInfo contains general information about NGINX Plus.
@@ -494,6 +495,19 @@ type HTTPLimitConnections map[string]LimitConnection
494
495
// StreamLimitConnections represents limit connections related stats
495
496
type StreamLimitConnections map [string ]LimitConnection
496
497
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
+
497
511
// NewNginxClient creates an NginxClient with the latest supported version.
498
512
func NewNginxClient (httpClient * http.Client , apiEndpoint string ) (* NginxClient , error ) {
499
513
return NewNginxClientWithVersion (httpClient , apiEndpoint , APIVersion )
@@ -1186,6 +1200,11 @@ func (client *NginxClient) GetStats() (*Stats, error) {
1186
1200
return nil , fmt .Errorf ("failed to get stats: %w" , err )
1187
1201
}
1188
1202
1203
+ workers , err := client .GetWorkers ()
1204
+ if err != nil {
1205
+ return nil , fmt .Errorf ("failed to get stats: %w" , err )
1206
+ }
1207
+
1189
1208
return & Stats {
1190
1209
NginxInfo : * info ,
1191
1210
Caches : * caches ,
@@ -1204,6 +1223,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
1204
1223
HTTPLimitRequests : * limitReqs ,
1205
1224
HTTPLimitConnections : * limitConnsHTTP ,
1206
1225
StreamLimitConnections : * limitConnsStream ,
1226
+ Workers : workers ,
1207
1227
}, nil
1208
1228
}
1209
1229
@@ -1639,3 +1659,16 @@ func (client *NginxClient) GetStreamConnectionsLimit() (*StreamLimitConnections,
1639
1659
}
1640
1660
return & limitConns , nil
1641
1661
}
1662
+
1663
+ // GetWorkers returns workers stats.
1664
+ func (client * NginxClient ) GetWorkers () ([]* Workers , error ) {
1665
+ var workers []* Workers
1666
+ if client .version < 9 {
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