storage: add metrics for db total size

release-2.3
Xiang Li 2015-10-05 16:15:44 -07:00
parent 699e37562e
commit 0aa2f1192a
5 changed files with 21 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import (
"hash/crc32"
"io"
"log"
"sync/atomic"
"time"
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
@ -28,6 +29,8 @@ type Backend interface {
BatchTx() BatchTx
Snapshot() Snapshot
Hash() (uint32, error)
// Size returns the current size of the backend.
Size() int64
ForceCommit()
Close() error
}
@ -47,6 +50,7 @@ type backend struct {
batchInterval time.Duration
batchLimit int
batchTx *batchTx
size int64
stopc chan struct{}
donec chan struct{}
@ -123,6 +127,10 @@ func (b *backend) Hash() (uint32, error) {
return h.Sum32(), nil
}
func (b *backend) Size() int64 {
return atomic.LoadInt64(&b.size)
}
func (b *backend) run() {
defer close(b.donec)

View File

@ -18,6 +18,7 @@ import (
"bytes"
"log"
"sync"
"sync/atomic"
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
)
@ -146,4 +147,5 @@ func (t *batchTx) commit(stop bool) {
if err != nil {
log.Fatalf("storage: cannot begin tx (%s)", err)
}
atomic.StoreInt64(&t.backend.size, t.tx.Size())
}

View File

@ -151,6 +151,8 @@ func (s *store) txnEnd(txnID int64) error {
s.currentRev.main += 1
}
s.currentRev.sub = 0
dbTotalSize.Set(float64(s.b.Size()))
s.mu.Unlock()
return nil
}

View File

@ -721,6 +721,7 @@ type fakeBackend struct {
func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx }
func (b *fakeBackend) Hash() (uint32, error) { return 0, nil }
func (b *fakeBackend) Size() int64 { return 0 }
func (b *fakeBackend) Snapshot() backend.Snapshot { return nil }
func (b *fakeBackend) ForceCommit() {}
func (b *fakeBackend) Close() error { return nil }

View File

@ -120,6 +120,13 @@ var (
// 100ms -> 800second
Buckets: prometheus.ExponentialBuckets(100, 2, 14),
})
dbTotalSize = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "etcd",
Subsystem: "storage",
Name: "db_total_size_in_bytes",
Help: "Total size of the underlying database in bytes.",
})
)
func init() {
@ -135,6 +142,7 @@ func init() {
prometheus.MustRegister(indexCompactionPauseDurations)
prometheus.MustRegister(dbCompactionPauseDurations)
prometheus.MustRegister(dbCompactionTotalDurations)
prometheus.MustRegister(dbTotalSize)
}
// ReportEventReceived reports that an event is received.