@@ -115,6 +115,7 @@ func (internalError *internalError) Wrap(err string) *internalError {
115
115
// https://nginx.org/en/docs/http/ngx_http_api_module.html
116
116
type Stats struct {
117
117
NginxInfo NginxInfo
118
+ Caches Caches
118
119
Processes Processes
119
120
Connections Connections
120
121
Slabs Slabs
@@ -141,6 +142,36 @@ type NginxInfo struct {
141
142
ParentProcessID uint64 `json:"ppid"`
142
143
}
143
144
145
+ // Caches is a map of cache stats by cache zone
146
+ type Caches = map [string ]HTTPCache
147
+
148
+ // HTTPCache represents a zone's HTTP Cache
149
+ type HTTPCache struct {
150
+ Size uint64
151
+ MaxSize uint64 `json:"max_size"`
152
+ Cold bool
153
+ Hit CacheStats
154
+ Stale CacheStats
155
+ Updating CacheStats
156
+ Revalidated CacheStats
157
+ Miss CacheStats
158
+ Expired ExtendedCacheStats
159
+ Bypass ExtendedCacheStats
160
+ }
161
+
162
+ // CacheStats are basic cache stats.
163
+ type CacheStats struct {
164
+ Responses uint64
165
+ Bytes uint64
166
+ }
167
+
168
+ // ExtendedCacheStats are extended cache stats.
169
+ type ExtendedCacheStats struct {
170
+ CacheStats
171
+ ResponsesWritten uint64 `json:"responses_written"`
172
+ BytesWritten uint64 `json:"bytes_written"`
173
+ }
174
+
144
175
// Connections represents connection related stats.
145
176
type Connections struct {
146
177
Accepted uint64
@@ -965,6 +996,11 @@ func (client *NginxClient) GetStats() (*Stats, error) {
965
996
return nil , fmt .Errorf ("failed to get stats: %v" , err )
966
997
}
967
998
999
+ caches , err := client .GetCaches ()
1000
+ if err != nil {
1001
+ return nil , fmt .Errorf ("failed to get stats: %v" , err )
1002
+ }
1003
+
968
1004
processes , err := client .GetProcesses ()
969
1005
if err != nil {
970
1006
return nil , fmt .Errorf ("failed to get stats: %v" , err )
@@ -1027,6 +1063,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
1027
1063
1028
1064
return & Stats {
1029
1065
NginxInfo : * info ,
1066
+ Caches : * caches ,
1030
1067
Processes : * processes ,
1031
1068
Slabs : * slabs ,
1032
1069
Connections : * cons ,
@@ -1052,6 +1089,16 @@ func (client *NginxClient) GetNginxInfo() (*NginxInfo, error) {
1052
1089
return & info , nil
1053
1090
}
1054
1091
1092
+ // GetCaches returns Cache stats
1093
+ func (client * NginxClient ) GetCaches () (* Caches , error ) {
1094
+ var caches Caches
1095
+ err := client .get ("http/caches" , & caches )
1096
+ if err != nil {
1097
+ return nil , fmt .Errorf ("failed to get caches: %v" , err )
1098
+ }
1099
+ return & caches , nil
1100
+ }
1101
+
1055
1102
// GetSlabs returns Slabs stats.
1056
1103
func (client * NginxClient ) GetSlabs () (* Slabs , error ) {
1057
1104
var slabs Slabs
0 commit comments