mirror of
https://github.com/pgsty/minio.git
synced 2026-07-20 04:30:26 +03:00
add bucket level S3 received/sent bytes (#15084)
adds bucket level metrics for bytes received and sent bytes on all S3 API calls.
This commit is contained in:
+113
-11
@@ -35,19 +35,21 @@ type ConnStats struct {
|
||||
totalOutputBytes uint64
|
||||
s3InputBytes uint64
|
||||
s3OutputBytes uint64
|
||||
adminInputBytes uint64
|
||||
adminOutputBytes uint64
|
||||
}
|
||||
|
||||
// Increase total input bytes
|
||||
// Increase internode total input bytes
|
||||
func (s *ConnStats) incInputBytes(n int64) {
|
||||
atomic.AddUint64(&s.totalInputBytes, uint64(n))
|
||||
}
|
||||
|
||||
// Increase total output bytes
|
||||
// Increase internode total output bytes
|
||||
func (s *ConnStats) incOutputBytes(n int64) {
|
||||
atomic.AddUint64(&s.totalOutputBytes, uint64(n))
|
||||
}
|
||||
|
||||
// Return total input bytes
|
||||
// Return internode total input bytes
|
||||
func (s *ConnStats) getTotalInputBytes() uint64 {
|
||||
return atomic.LoadUint64(&s.totalInputBytes)
|
||||
}
|
||||
@@ -57,33 +59,55 @@ func (s *ConnStats) getTotalOutputBytes() uint64 {
|
||||
return atomic.LoadUint64(&s.totalOutputBytes)
|
||||
}
|
||||
|
||||
// Increase outbound input bytes
|
||||
// Increase S3 total input bytes
|
||||
func (s *ConnStats) incS3InputBytes(n int64) {
|
||||
atomic.AddUint64(&s.s3InputBytes, uint64(n))
|
||||
}
|
||||
|
||||
// Increase outbound output bytes
|
||||
// Increase S3 total output bytes
|
||||
func (s *ConnStats) incS3OutputBytes(n int64) {
|
||||
atomic.AddUint64(&s.s3OutputBytes, uint64(n))
|
||||
}
|
||||
|
||||
// Return outbound input bytes
|
||||
// Return S3 total input bytes
|
||||
func (s *ConnStats) getS3InputBytes() uint64 {
|
||||
return atomic.LoadUint64(&s.s3InputBytes)
|
||||
}
|
||||
|
||||
// Return outbound output bytes
|
||||
// Return S3 total output bytes
|
||||
func (s *ConnStats) getS3OutputBytes() uint64 {
|
||||
return atomic.LoadUint64(&s.s3OutputBytes)
|
||||
}
|
||||
|
||||
// Increase Admin total input bytes
|
||||
func (s *ConnStats) incAdminInputBytes(n int64) {
|
||||
atomic.AddUint64(&s.adminInputBytes, uint64(n))
|
||||
}
|
||||
|
||||
// Increase Admin total output bytes
|
||||
func (s *ConnStats) incAdminOutputBytes(n int64) {
|
||||
atomic.AddUint64(&s.adminOutputBytes, uint64(n))
|
||||
}
|
||||
|
||||
// Return Admin total input bytes
|
||||
func (s *ConnStats) getAdminInputBytes() uint64 {
|
||||
return atomic.LoadUint64(&s.adminInputBytes)
|
||||
}
|
||||
|
||||
// Return Admin total output bytes
|
||||
func (s *ConnStats) getAdminOutputBytes() uint64 {
|
||||
return atomic.LoadUint64(&s.adminOutputBytes)
|
||||
}
|
||||
|
||||
// Return connection stats (total input/output bytes and total s3 input/output bytes)
|
||||
func (s *ConnStats) toServerConnStats() ServerConnStats {
|
||||
return ServerConnStats{
|
||||
TotalInputBytes: s.getTotalInputBytes(), // Traffic including reserved bucket
|
||||
TotalOutputBytes: s.getTotalOutputBytes(), // Traffic including reserved bucket
|
||||
S3InputBytes: s.getS3InputBytes(), // Traffic for client buckets
|
||||
S3OutputBytes: s.getS3OutputBytes(), // Traffic for client buckets
|
||||
TotalInputBytes: s.getTotalInputBytes(), // Traffic internode received
|
||||
TotalOutputBytes: s.getTotalOutputBytes(), // Traffic internode sent
|
||||
S3InputBytes: s.getS3InputBytes(), // Traffic S3 received
|
||||
S3OutputBytes: s.getS3OutputBytes(), // Traffic S3 sent
|
||||
AdminInputBytes: s.getAdminInputBytes(), // Traffic admin calls received
|
||||
AdminOutputBytes: s.getAdminOutputBytes(), // Traffic admin calls sent
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +116,84 @@ func newConnStats() *ConnStats {
|
||||
return &ConnStats{}
|
||||
}
|
||||
|
||||
type bucketS3RXTX struct {
|
||||
s3InputBytes uint64
|
||||
s3OutputBytes uint64
|
||||
}
|
||||
|
||||
type bucketConnStats struct {
|
||||
sync.RWMutex
|
||||
stats map[string]*bucketS3RXTX
|
||||
}
|
||||
|
||||
func newBucketConnStats() *bucketConnStats {
|
||||
return &bucketConnStats{
|
||||
stats: make(map[string]*bucketS3RXTX),
|
||||
}
|
||||
}
|
||||
|
||||
// Increase S3 total input bytes for input bucket
|
||||
func (s *bucketConnStats) incS3InputBytes(bucket string, n int64) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
stats, ok := s.stats[bucket]
|
||||
if !ok {
|
||||
stats = &bucketS3RXTX{
|
||||
s3InputBytes: uint64(n),
|
||||
}
|
||||
} else {
|
||||
stats.s3InputBytes += uint64(n)
|
||||
}
|
||||
s.stats[bucket] = stats
|
||||
}
|
||||
|
||||
// Increase S3 total output bytes for input bucket
|
||||
func (s *bucketConnStats) incS3OutputBytes(bucket string, n int64) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
stats, ok := s.stats[bucket]
|
||||
if !ok {
|
||||
stats = &bucketS3RXTX{
|
||||
s3OutputBytes: uint64(n),
|
||||
}
|
||||
} else {
|
||||
stats.s3OutputBytes += uint64(n)
|
||||
}
|
||||
s.stats[bucket] = stats
|
||||
}
|
||||
|
||||
// Return S3 total input bytes for input bucket
|
||||
func (s *bucketConnStats) getS3InputBytes(bucket string) uint64 {
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
|
||||
stats := s.stats[bucket]
|
||||
if stats == nil {
|
||||
return 0
|
||||
}
|
||||
return stats.s3InputBytes
|
||||
}
|
||||
|
||||
// Return S3 total output bytes
|
||||
func (s *bucketConnStats) getS3OutputBytes(bucket string) uint64 {
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
|
||||
stats := s.stats[bucket]
|
||||
if stats == nil {
|
||||
return 0
|
||||
}
|
||||
return stats.s3OutputBytes
|
||||
}
|
||||
|
||||
// delete metrics once bucket is deleted.
|
||||
func (s *bucketConnStats) delete(bucket string) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
delete(s.stats, bucket)
|
||||
}
|
||||
|
||||
// HTTPAPIStats holds statistics information about
|
||||
// a given API in the requests.
|
||||
type HTTPAPIStats struct {
|
||||
|
||||
Reference in New Issue
Block a user