Skip to content

Commit

Permalink
feat: add metrics etcd_debugging_lease_total
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy- <zhenguo251@gmail.com>
  • Loading branch information
jimmy-bro committed May 25, 2024
1 parent d0ea231 commit 3398eed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/lease/lessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func (le *lessor) Grant(id LeaseID, ttl int64) (*Lease, error) {

leaseTotalTTLs.Observe(float64(l.ttl))
leaseGranted.Inc()
leaseTotal.Inc()

if le.isPrimary() {
item := &LeaseWithTime{id: l.ID, time: l.expiry}
Expand Down Expand Up @@ -351,6 +352,7 @@ func (le *lessor) Revoke(id LeaseID) error {
txn.End()

leaseRevoked.Inc()
leaseTotal.Dec()
return nil
}

Expand Down Expand Up @@ -812,6 +814,7 @@ func (le *lessor) initAndRecover() {
}
le.leaseExpiredNotifier.Init()
heap.Init(&le.leaseCheckpointHeap)
leaseTotal.Set(float64(len(le.leaseMap)))

le.b.ForceCommit()
}
Expand Down
8 changes: 8 additions & 0 deletions server/lease/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ var (
// 1 second -> 3 months
Buckets: prometheus.ExponentialBuckets(1, 2, 24),
})

leaseTotal = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "etcd_debugging",
Subsystem: "lease",
Name: "total",
Help: "The total number of active leases.",
})
)

func init() {
prometheus.MustRegister(leaseGranted)
prometheus.MustRegister(leaseRevoked)
prometheus.MustRegister(leaseRenewed)
prometheus.MustRegister(leaseTotalTTLs)
prometheus.MustRegister(leaseTotal)
}
1 change: 1 addition & 0 deletions server/lease/metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package lease

0 comments on commit 3398eed

Please sign in to comment.