storage: add metrics for db total size
parent
699e37562e
commit
0aa2f1192a
|
@ -19,6 +19,7 @@ import (
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
|
||||||
|
@ -28,6 +29,8 @@ type Backend interface {
|
||||||
BatchTx() BatchTx
|
BatchTx() BatchTx
|
||||||
Snapshot() Snapshot
|
Snapshot() Snapshot
|
||||||
Hash() (uint32, error)
|
Hash() (uint32, error)
|
||||||
|
// Size returns the current size of the backend.
|
||||||
|
Size() int64
|
||||||
ForceCommit()
|
ForceCommit()
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
@ -47,6 +50,7 @@ type backend struct {
|
||||||
batchInterval time.Duration
|
batchInterval time.Duration
|
||||||
batchLimit int
|
batchLimit int
|
||||||
batchTx *batchTx
|
batchTx *batchTx
|
||||||
|
size int64
|
||||||
|
|
||||||
stopc chan struct{}
|
stopc chan struct{}
|
||||||
donec chan struct{}
|
donec chan struct{}
|
||||||
|
@ -123,6 +127,10 @@ func (b *backend) Hash() (uint32, error) {
|
||||||
return h.Sum32(), nil
|
return h.Sum32(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *backend) Size() int64 {
|
||||||
|
return atomic.LoadInt64(&b.size)
|
||||||
|
}
|
||||||
|
|
||||||
func (b *backend) run() {
|
func (b *backend) run() {
|
||||||
defer close(b.donec)
|
defer close(b.donec)
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt"
|
||||||
)
|
)
|
||||||
|
@ -146,4 +147,5 @@ func (t *batchTx) commit(stop bool) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("storage: cannot begin tx (%s)", err)
|
log.Fatalf("storage: cannot begin tx (%s)", err)
|
||||||
}
|
}
|
||||||
|
atomic.StoreInt64(&t.backend.size, t.tx.Size())
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,8 @@ func (s *store) txnEnd(txnID int64) error {
|
||||||
s.currentRev.main += 1
|
s.currentRev.main += 1
|
||||||
}
|
}
|
||||||
s.currentRev.sub = 0
|
s.currentRev.sub = 0
|
||||||
|
|
||||||
|
dbTotalSize.Set(float64(s.b.Size()))
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -721,6 +721,7 @@ type fakeBackend struct {
|
||||||
|
|
||||||
func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx }
|
func (b *fakeBackend) BatchTx() backend.BatchTx { return b.tx }
|
||||||
func (b *fakeBackend) Hash() (uint32, error) { return 0, nil }
|
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) Snapshot() backend.Snapshot { return nil }
|
||||||
func (b *fakeBackend) ForceCommit() {}
|
func (b *fakeBackend) ForceCommit() {}
|
||||||
func (b *fakeBackend) Close() error { return nil }
|
func (b *fakeBackend) Close() error { return nil }
|
||||||
|
|
|
@ -120,6 +120,13 @@ var (
|
||||||
// 100ms -> 800second
|
// 100ms -> 800second
|
||||||
Buckets: prometheus.ExponentialBuckets(100, 2, 14),
|
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() {
|
func init() {
|
||||||
|
@ -135,6 +142,7 @@ func init() {
|
||||||
prometheus.MustRegister(indexCompactionPauseDurations)
|
prometheus.MustRegister(indexCompactionPauseDurations)
|
||||||
prometheus.MustRegister(dbCompactionPauseDurations)
|
prometheus.MustRegister(dbCompactionPauseDurations)
|
||||||
prometheus.MustRegister(dbCompactionTotalDurations)
|
prometheus.MustRegister(dbCompactionTotalDurations)
|
||||||
|
prometheus.MustRegister(dbTotalSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReportEventReceived reports that an event is received.
|
// ReportEventReceived reports that an event is received.
|
||||||
|
|
Loading…
Reference in New Issue