forked from minio/minio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for Cache and S3 related metrics in Prometheus endpoint (m…
…inio#8591) This PR adds support below metrics - Cache Hit Count - Cache Miss Count - Data served from Cache (in Bytes) - Bytes received from AWS S3 - Bytes sent to AWS S3 - Number of requests sent to AWS S3 Fixes minio#8549
- Loading branch information
1 parent
d2dc964
commit 3df7285
Showing
32 changed files
with
400 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* MinIO Cloud Storage, (C) 2019 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"go.uber.org/atomic" | ||
) | ||
|
||
// CacheStats - represents bytes served from cache, | ||
// cache hits and cache misses. | ||
type CacheStats struct { | ||
BytesServed atomic.Uint64 | ||
Hits atomic.Uint64 | ||
Misses atomic.Uint64 | ||
} | ||
|
||
// Increase total bytes served from cache | ||
func (s *CacheStats) incBytesServed(n int64) { | ||
s.BytesServed.Add(uint64(n)) | ||
} | ||
|
||
// Increase cache hit by 1 | ||
func (s *CacheStats) incHit() { | ||
s.Hits.Add(uint64(1)) | ||
} | ||
|
||
// Increase cache miss by 1 | ||
func (s *CacheStats) incMiss() { | ||
s.Misses.Add(uint64(1)) | ||
} | ||
|
||
// Get total bytes served | ||
func (s *CacheStats) getBytesServed() uint64 { | ||
return s.BytesServed.Load() | ||
} | ||
|
||
// Get total cache hits | ||
func (s *CacheStats) getHits() uint64 { | ||
return s.Hits.Load() | ||
} | ||
|
||
// Get total cache misses | ||
func (s *CacheStats) getMisses() uint64 { | ||
return s.Misses.Load() | ||
} | ||
|
||
// Prepare new CacheStats structure | ||
func newCacheStats() *CacheStats { | ||
return &CacheStats{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* MinIO Cloud Storage, (C) 2019 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"sync" | ||
|
||
"go.uber.org/atomic" | ||
) | ||
|
||
// Metrics - represents bytes served from backend | ||
// only implemented for S3 Gateway | ||
type Metrics struct { | ||
BytesReceived atomic.Uint64 | ||
BytesSent atomic.Uint64 | ||
RequestStats map[string]int | ||
sync.RWMutex | ||
} | ||
|
||
// IncBytesReceived - Increase total bytes received from gateway backend | ||
func (s *Metrics) IncBytesReceived(n int64) { | ||
s.BytesReceived.Add(uint64(n)) | ||
} | ||
|
||
// GetBytesReceived - Get total bytes received from gateway backend | ||
func (s *Metrics) GetBytesReceived() uint64 { | ||
return s.BytesReceived.Load() | ||
} | ||
|
||
// IncBytesSent - Increase total bytes sent to gateway backend | ||
func (s *Metrics) IncBytesSent(n int64) { | ||
s.BytesSent.Add(uint64(n)) | ||
} | ||
|
||
// GetBytesSent - Get total bytes received from gateway backend | ||
func (s *Metrics) GetBytesSent() uint64 { | ||
return s.BytesSent.Load() | ||
} | ||
|
||
// IncRequests - Increase request sent to gateway backend by 1 | ||
func (s *Metrics) IncRequests(method string) { | ||
s.Lock() | ||
defer s.Unlock() | ||
if s == nil { | ||
return | ||
} | ||
if s.RequestStats == nil { | ||
s.RequestStats = make(map[string]int) | ||
} | ||
if _, ok := s.RequestStats[method]; ok { | ||
s.RequestStats[method]++ | ||
return | ||
} | ||
s.RequestStats[method] = 1 | ||
} | ||
|
||
// GetRequests - Get total number of requests sent to gateway backend | ||
func (s *Metrics) GetRequests() map[string]int { | ||
return s.RequestStats | ||
} | ||
|
||
// NewMetrics - Prepare new Metrics structure | ||
func NewMetrics() *Metrics { | ||
return &Metrics{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.