Skip to content

Commit

Permalink
Merge pull request #11374 from YoyinZyc/put_throughput_metrics
Browse files Browse the repository at this point in the history
mvcc: add "etcd_mvcc_put_size_in_bytes" metrics
  • Loading branch information
jingyih committed Nov 20, 2019
2 parents b373cb9 + a5e747b commit 908ef19
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions mvcc/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ var (
// overridden by mvcc initialization
reportCompactRevMu sync.RWMutex
reportCompactRev = func() float64 { return 0 }

totalPutSizeGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "etcd_debugging",
Subsystem: "mvcc",
Name: "total_put_size_in_bytes",
Help: "The total size of put kv pairs seen by this member.",
})
)

func init() {
Expand Down Expand Up @@ -325,6 +333,7 @@ func init() {
prometheus.MustRegister(hashRevSec)
prometheus.MustRegister(currentRev)
prometheus.MustRegister(compactRev)
prometheus.MustRegister(totalPutSizeGauge)
}

// ReportEventReceived reports that an event is received.
Expand Down
8 changes: 6 additions & 2 deletions mvcc/metrics_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ type metricsTxnWrite struct {
ranges uint
puts uint
deletes uint
putSize int64
}

func newMetricsTxnRead(tr TxnRead) TxnRead {
return &metricsTxnWrite{&txnReadWrite{tr}, 0, 0, 0}
return &metricsTxnWrite{&txnReadWrite{tr}, 0, 0, 0, 0}
}

func newMetricsTxnWrite(tw TxnWrite) TxnWrite {
return &metricsTxnWrite{tw, 0, 0, 0}
return &metricsTxnWrite{tw, 0, 0, 0, 0}
}

func (tw *metricsTxnWrite) Range(key, end []byte, ro RangeOptions) (*RangeResult, error) {
Expand All @@ -43,6 +44,8 @@ func (tw *metricsTxnWrite) DeleteRange(key, end []byte) (n, rev int64) {

func (tw *metricsTxnWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) {
tw.puts++
size := int64(len(key) + len(value))
tw.putSize += size
return tw.TxnWrite.Put(key, value, lease)
}

Expand All @@ -60,6 +63,7 @@ func (tw *metricsTxnWrite) End() {
puts := float64(tw.puts)
putCounter.Add(puts)
putCounterDebug.Add(puts) // TODO: remove in 3.5 release
totalPutSizeGauge.Add(float64(tw.putSize))

deletes := float64(tw.deletes)
deleteCounter.Add(deletes)
Expand Down

0 comments on commit 908ef19

Please sign in to comment.