@@ -115,6 +115,7 @@ func (internalError *internalError) Wrap(err string) *internalError {
115115// https://nginx.org/en/docs/http/ngx_http_api_module.html
116116type Stats struct {
117117 NginxInfo NginxInfo
118+ Caches Caches
118119 Processes Processes
119120 Connections Connections
120121 Slabs Slabs
@@ -141,6 +142,36 @@ type NginxInfo struct {
141142 ParentProcessID uint64 `json:"ppid"`
142143}
143144
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+
144175// Connections represents connection related stats.
145176type Connections struct {
146177 Accepted uint64
@@ -965,6 +996,11 @@ func (client *NginxClient) GetStats() (*Stats, error) {
965996 return nil , fmt .Errorf ("failed to get stats: %v" , err )
966997 }
967998
999+ caches , err := client .GetCaches ()
1000+ if err != nil {
1001+ return nil , fmt .Errorf ("failed to get stats: %v" , err )
1002+ }
1003+
9681004 processes , err := client .GetProcesses ()
9691005 if err != nil {
9701006 return nil , fmt .Errorf ("failed to get stats: %v" , err )
@@ -1027,6 +1063,7 @@ func (client *NginxClient) GetStats() (*Stats, error) {
10271063
10281064 return & Stats {
10291065 NginxInfo : * info ,
1066+ Caches : * caches ,
10301067 Processes : * processes ,
10311068 Slabs : * slabs ,
10321069 Connections : * cons ,
@@ -1052,6 +1089,16 @@ func (client *NginxClient) GetNginxInfo() (*NginxInfo, error) {
10521089 return & info , nil
10531090}
10541091
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+
10551102// GetSlabs returns Slabs stats.
10561103func (client * NginxClient ) GetSlabs () (* Slabs , error ) {
10571104 var slabs Slabs
0 commit comments