storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/disk-cache-stats.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2019, 2020 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package cmd 18 19 import ( 20 "sync/atomic" 21 ) 22 23 // CacheDiskStats represents cache disk statistics 24 // such as current disk usage and available. 25 type CacheDiskStats struct { 26 // used cache size 27 UsageSize uint64 28 // total cache disk capacity 29 TotalCapacity uint64 30 // indicates if usage is high or low, if high value is '1', if low its '0' 31 UsageState int32 32 // indicates the current usage percentage of this cache disk 33 UsagePercent uint64 34 Dir string 35 } 36 37 // GetUsageLevelString gets the string representation for the usage level. 38 func (c *CacheDiskStats) GetUsageLevelString() (u string) { 39 if atomic.LoadInt32(&c.UsageState) == 0 { 40 return "low" 41 } 42 return "high" 43 } 44 45 // CacheStats - represents bytes served from cache, 46 // cache hits and cache misses. 47 type CacheStats struct { 48 BytesServed uint64 49 Hits uint64 50 Misses uint64 51 GetDiskStats func() []CacheDiskStats 52 } 53 54 // Increase total bytes served from cache 55 func (s *CacheStats) incBytesServed(n int64) { 56 atomic.AddUint64(&s.BytesServed, uint64(n)) 57 } 58 59 // Increase cache hit by 1 60 func (s *CacheStats) incHit() { 61 atomic.AddUint64(&s.Hits, 1) 62 } 63 64 // Increase cache miss by 1 65 func (s *CacheStats) incMiss() { 66 atomic.AddUint64(&s.Misses, 1) 67 } 68 69 // Get total bytes served 70 func (s *CacheStats) getBytesServed() uint64 { 71 return atomic.LoadUint64(&s.BytesServed) 72 } 73 74 // Get total cache hits 75 func (s *CacheStats) getHits() uint64 { 76 return atomic.LoadUint64(&s.Hits) 77 } 78 79 // Get total cache misses 80 func (s *CacheStats) getMisses() uint64 { 81 return atomic.LoadUint64(&s.Misses) 82 } 83 84 // Prepare new CacheStats structure 85 func newCacheStats() *CacheStats { 86 return &CacheStats{} 87 }