Add Audit target metrics (#16044)

This commit is contained in:
Klaus Post
2022-11-10 19:20:21 +01:00
committed by GitHub
parent 34d28dd79f
commit 5b242f1d11
8 changed files with 233 additions and 32 deletions

View File

@@ -18,6 +18,8 @@
package logger
import (
"fmt"
"strings"
"sync"
"github.com/minio/minio/internal/logger/target/http"
@@ -32,6 +34,7 @@ import (
type Target interface {
String() string
Endpoint() string
Stats() types.TargetStats
Init() error
Cancel()
Send(entry interface{}) error
@@ -71,6 +74,33 @@ func AuditTargets() []Target {
return res
}
// CurrentStats returns the current statistics.
func CurrentStats() map[string]types.TargetStats {
sys := SystemTargets()
audit := AuditTargets()
res := make(map[string]types.TargetStats, len(sys)+len(audit))
cnt := make(map[string]int, len(sys)+len(audit))
// Add system and audit.
for _, t := range sys {
key := strings.ToLower(t.Type().String())
n := cnt[key]
cnt[key]++
key = fmt.Sprintf("sys_%s_%d", key, n)
res[key] = t.Stats()
}
for _, t := range audit {
key := strings.ToLower(t.Type().String())
n := cnt[key]
cnt[key]++
key = fmt.Sprintf("audit_%s_%d", key, n)
res[key] = t.Stats()
}
return res
}
// auditTargets is the list of enabled audit loggers
// Must be immutable at all times.
// Can be swapped to another while holding swapMu