统计缓存
(message *pb.NodeStreamMessage)
| 258 | |
| 259 | // 统计缓存 |
| 260 | func (this *APIStream) handleStatCache(message *pb.NodeStreamMessage) error { |
| 261 | msg := &messageconfigs.ReadCacheMessage{} |
| 262 | err := json.Unmarshal(message.DataJSON, msg) |
| 263 | if err != nil { |
| 264 | this.replyFail(message.RequestId, "decode message data failed: "+err.Error()) |
| 265 | return err |
| 266 | } |
| 267 | |
| 268 | storage, shouldStop, err := this.cacheStorage(message, msg.CachePolicyJSON) |
| 269 | if err != nil { |
| 270 | return err |
| 271 | } |
| 272 | if shouldStop { |
| 273 | defer func() { |
| 274 | storage.Stop() |
| 275 | }() |
| 276 | } |
| 277 | |
| 278 | stat, err := storage.Stat() |
| 279 | if err != nil { |
| 280 | this.replyFail(message.RequestId, "stat failed: "+err.Error()) |
| 281 | return err |
| 282 | } |
| 283 | |
| 284 | sizeFormat := "" |
| 285 | if stat.Size < (1 << 10) { |
| 286 | sizeFormat = strconv.FormatInt(stat.Size, 10) + " Bytes" |
| 287 | } else if stat.Size < (1 << 20) { |
| 288 | sizeFormat = fmt.Sprintf("%.2f KiB", float64(stat.Size)/(1<<10)) |
| 289 | } else if stat.Size < (1 << 30) { |
| 290 | sizeFormat = fmt.Sprintf("%.2f MiB", float64(stat.Size)/(1<<20)) |
| 291 | } else { |
| 292 | sizeFormat = fmt.Sprintf("%.2f GiB", float64(stat.Size)/(1<<30)) |
| 293 | } |
| 294 | this.replyOk(message.RequestId, "size:"+sizeFormat+", count:"+strconv.Itoa(stat.Count)) |
| 295 | |
| 296 | return nil |
| 297 | } |
| 298 | |
| 299 | // 清理缓存 |
| 300 | func (this *APIStream) handleCleanCache(message *pb.NodeStreamMessage) error { |