From 3b7781835e706a9f09bde96e20082167edbea613 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 3 Apr 2023 21:23:24 -0700 Subject: [PATCH] add lock metrics per node (#16943) --- cmd/local-locker.go | 29 ++++++++++++++++++++++++ cmd/metrics-v2.go | 54 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/cmd/local-locker.go b/cmd/local-locker.go index c6e9a3ffb..dd609e759 100644 --- a/cmd/local-locker.go +++ b/cmd/local-locker.go @@ -213,12 +213,41 @@ func (l *localLocker) RUnlock(_ context.Context, args dsync.LockArgs) (reply boo return reply, nil } +type lockStats struct { + Total int + Writes int + Reads int +} + +func (l *localLocker) stats() lockStats { + l.mutex.Lock() + defer l.mutex.Unlock() + + st := lockStats{Total: len(l.lockMap)} + for _, v := range l.lockMap { + if len(v) == 0 { + continue + } + entry := v[0] + if entry.Writer { + st.Writes++ + } else { + st.Reads += len(v) + } + } + return st +} + func (l *localLocker) DupLockMap() map[string][]lockRequesterInfo { l.mutex.Lock() defer l.mutex.Unlock() lockCopy := make(map[string][]lockRequesterInfo, len(l.lockMap)) for k, v := range l.lockMap { + if len(v) == 0 { + delete(l.lockMap, k) + continue + } lockCopy[k] = append(make([]lockRequesterInfo, 0, len(v)), v...) } return lockCopy diff --git a/cmd/metrics-v2.go b/cmd/metrics-v2.go index b9d50609e..8331c5e94 100644 --- a/cmd/metrics-v2.go +++ b/cmd/metrics-v2.go @@ -77,7 +77,7 @@ func init() { return allMetrics }() - nodeCollector = newMinioCollectorNode([]*MetricsGroup{ + nodeGroups := []*MetricsGroup{ getNodeHealthMetrics(), getLocalDriveStorageMetrics(), getCacheMetrics(), @@ -86,7 +86,10 @@ func init() { getMinioVersionMetrics(), getS3TTFBMetric(), getNotificationMetrics(), - }) + getDistLockMetrics(), + } + + nodeCollector = newMinioCollectorNode(nodeGroups) clusterCollector = newMinioClusterCollector(allMetricsGroups) } @@ -1663,6 +1666,53 @@ func getCacheMetrics() *MetricsGroup { return mg } +func getDistLockMetrics() *MetricsGroup { + mg := &MetricsGroup{ + cacheInterval: 1 * time.Second, + } + mg.RegisterRead(func(ctx context.Context) []Metric { + if !globalIsDistErasure { + return []Metric{} + } + + st := globalLockServer.stats() + + metrics := make([]Metric, 0, 3) + metrics = append(metrics, Metric{ + Description: MetricDescription{ + Namespace: minioNamespace, + Subsystem: "locks", + Name: "total", + Help: "Number of current locks on this peer", + Type: gaugeMetric, + }, + Value: float64(st.Total), + }) + metrics = append(metrics, Metric{ + Description: MetricDescription{ + Namespace: minioNamespace, + Subsystem: "locks", + Name: "write_total", + Help: "Number of current WRITE locks on this peer", + Type: gaugeMetric, + }, + Value: float64(st.Writes), + }) + metrics = append(metrics, Metric{ + Description: MetricDescription{ + Namespace: minioNamespace, + Subsystem: "locks", + Name: "read_total", + Help: "Number of current READ locks on this peer", + Type: gaugeMetric, + }, + Value: float64(st.Reads), + }) + return metrics + }) + return mg +} + func getNotificationMetrics() *MetricsGroup { mg := &MetricsGroup{ cacheInterval: 10 * time.Second,