Skip to content

Commit 1d1c4c2

Browse files
author
Faisal Memon
committed
Add functionality to get /slabs
1 parent 9a147f5 commit 1d1c4c2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

client/nginx.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func (internalError *internalError) Wrap(err string) *internalError {
109109
type Stats struct {
110110
NginxInfo NginxInfo
111111
Connections Connections
112+
Slabs Slabs
112113
HTTPRequests HTTPRequests
113114
SSL SSL
114115
ServerZones ServerZones
@@ -140,6 +141,20 @@ type Connections struct {
140141
Idle uint64
141142
}
142143

144+
// Slabs is map of slab stats by zone name.
145+
type Slabs map[string]Slab
146+
147+
// Slab represents slab related stats.
148+
type Slab struct {
149+
Pages Pages
150+
}
151+
152+
// Pages represents the slab memory usage stats.
153+
type Pages struct {
154+
Used uint64
155+
Free uint64
156+
}
157+
143158
// HTTPRequests represents HTTP request related stats.
144159
type HTTPRequests struct {
145160
Total uint64
@@ -910,6 +925,11 @@ func (client *NginxClient) GetStats() (*Stats, error) {
910925
return nil, fmt.Errorf("failed to get stats %v", err)
911926
}
912927

928+
slabs, err := client.getSlabs()
929+
if err != nil {
930+
return nil, fmt.Errorf("failed to get stats %v", err)
931+
}
932+
913933
cons, err := client.getConnections()
914934
if err != nil {
915935
return nil, fmt.Errorf("failed to get stats: %v", err)
@@ -962,6 +982,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
962982

963983
return &Stats{
964984
NginxInfo: *info,
985+
Slabs: *slabs,
965986
Connections: *cons,
966987
HTTPRequests: *requests,
967988
SSL: *ssl,
@@ -984,6 +1005,15 @@ func (client *NginxClient) getNginxInfo() (*NginxInfo, error) {
9841005
return &info, nil
9851006
}
9861007

1008+
func (client *NginxClient) getSlabs() (*Slabs, error) {
1009+
var slabs Slabs
1010+
err := client.get("slabs", &slabs)
1011+
if err != nil {
1012+
return nil, fmt.Errorf("failed to get slabs: %v", err)
1013+
}
1014+
return &slabs, nil
1015+
}
1016+
9871017
func (client *NginxClient) getConnections() (*Connections, error) {
9881018
var cons Connections
9891019
err := client.get("connections", &cons)

0 commit comments

Comments
 (0)