Skip to content

Commit

Permalink
feat: add etcd_debugging_lease_total gauge metric
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy- <zhenguo251@gmail.com>
  • Loading branch information
jimmy-bro committed Jun 3, 2024
1 parent 0b2f15f commit a9a668f
Show file tree
Hide file tree
Showing 2 changed files with 11 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()
leaseActive.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()
leaseActive.Dec()
return nil
}

Expand Down Expand Up @@ -812,6 +814,7 @@ func (le *lessor) initAndRecover() {
}
le.leaseExpiredNotifier.Init()
heap.Init(&le.leaseCheckpointHeap)
leaseActive.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),
})

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

func init() {
prometheus.MustRegister(leaseGranted)
prometheus.MustRegister(leaseRevoked)
prometheus.MustRegister(leaseRenewed)
prometheus.MustRegister(leaseTotalTTLs)
prometheus.MustRegister(leaseActive)
}

0 comments on commit a9a668f

Please sign in to comment.