mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
Merge pull request #375 from codesome/symbol-table-size
Added metric for symbol table size
This commit is contained in:
commit
d9129adb52
21
block.go
21
block.go
|
@ -15,6 +15,7 @@
|
||||||
package tsdb
|
package tsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -248,6 +249,10 @@ type Block struct {
|
||||||
dir string
|
dir string
|
||||||
meta BlockMeta
|
meta BlockMeta
|
||||||
|
|
||||||
|
// Symbol Table Size in bytes.
|
||||||
|
// We maintain this variable to avoid recalculation everytime.
|
||||||
|
symbolTableSize uint64
|
||||||
|
|
||||||
chunkr ChunkReader
|
chunkr ChunkReader
|
||||||
indexr IndexReader
|
indexr IndexReader
|
||||||
tombstones TombstoneReader
|
tombstones TombstoneReader
|
||||||
|
@ -275,12 +280,23 @@ func OpenBlock(dir string, pool chunkenc.Pool) (*Block, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculating symbol table size.
|
||||||
|
tmp := make([]byte, 8)
|
||||||
|
symTblSize := uint64(0)
|
||||||
|
for _, v := range ir.SymbolTable() {
|
||||||
|
// Size of varint length of the symbol.
|
||||||
|
symTblSize += uint64(binary.PutUvarint(tmp, uint64(len(v))))
|
||||||
|
// Size of the symbol.
|
||||||
|
symTblSize += uint64(len(v))
|
||||||
|
}
|
||||||
|
|
||||||
pb := &Block{
|
pb := &Block{
|
||||||
dir: dir,
|
dir: dir,
|
||||||
meta: *meta,
|
meta: *meta,
|
||||||
chunkr: cr,
|
chunkr: cr,
|
||||||
indexr: ir,
|
indexr: ir,
|
||||||
tombstones: tr,
|
tombstones: tr,
|
||||||
|
symbolTableSize: symTblSize,
|
||||||
}
|
}
|
||||||
return pb, nil
|
return pb, nil
|
||||||
}
|
}
|
||||||
|
@ -350,6 +366,11 @@ func (pb *Block) Tombstones() (TombstoneReader, error) {
|
||||||
return blockTombstoneReader{TombstoneReader: pb.tombstones, b: pb}, nil
|
return blockTombstoneReader{TombstoneReader: pb.tombstones, b: pb}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSymbolTableSize returns the Symbol Table Size in the index of this block.
|
||||||
|
func (pb *Block) GetSymbolTableSize() uint64 {
|
||||||
|
return pb.symbolTableSize
|
||||||
|
}
|
||||||
|
|
||||||
func (pb *Block) setCompactionFailed() error {
|
func (pb *Block) setCompactionFailed() error {
|
||||||
pb.meta.Compaction.Failed = true
|
pb.meta.Compaction.Failed = true
|
||||||
return writeMetaFile(pb.dir, &pb.meta)
|
return writeMetaFile(pb.dir, &pb.meta)
|
||||||
|
|
15
db.go
15
db.go
|
@ -119,6 +119,7 @@ type DB struct {
|
||||||
|
|
||||||
type dbMetrics struct {
|
type dbMetrics struct {
|
||||||
loadedBlocks prometheus.GaugeFunc
|
loadedBlocks prometheus.GaugeFunc
|
||||||
|
symbolTableSize prometheus.GaugeFunc
|
||||||
reloads prometheus.Counter
|
reloads prometheus.Counter
|
||||||
reloadsFailed prometheus.Counter
|
reloadsFailed prometheus.Counter
|
||||||
compactionsTriggered prometheus.Counter
|
compactionsTriggered prometheus.Counter
|
||||||
|
@ -138,6 +139,19 @@ func newDBMetrics(db *DB, r prometheus.Registerer) *dbMetrics {
|
||||||
defer db.mtx.RUnlock()
|
defer db.mtx.RUnlock()
|
||||||
return float64(len(db.blocks))
|
return float64(len(db.blocks))
|
||||||
})
|
})
|
||||||
|
m.symbolTableSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||||
|
Name: "prometheus_tsdb_symbol_table_size",
|
||||||
|
Help: "Size of symbol table on disk (in bytes)",
|
||||||
|
}, func() float64 {
|
||||||
|
db.mtx.RLock()
|
||||||
|
blocks := db.blocks[:]
|
||||||
|
db.mtx.RUnlock()
|
||||||
|
symTblSize := float64(0)
|
||||||
|
for _, b := range blocks {
|
||||||
|
symTblSize += float64(b.GetSymbolTableSize())
|
||||||
|
}
|
||||||
|
return symTblSize
|
||||||
|
})
|
||||||
m.reloads = prometheus.NewCounter(prometheus.CounterOpts{
|
m.reloads = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
Name: "prometheus_tsdb_reloads_total",
|
Name: "prometheus_tsdb_reloads_total",
|
||||||
Help: "Number of times the database reloaded block data from disk.",
|
Help: "Number of times the database reloaded block data from disk.",
|
||||||
|
@ -166,6 +180,7 @@ func newDBMetrics(db *DB, r prometheus.Registerer) *dbMetrics {
|
||||||
if r != nil {
|
if r != nil {
|
||||||
r.MustRegister(
|
r.MustRegister(
|
||||||
m.loadedBlocks,
|
m.loadedBlocks,
|
||||||
|
m.symbolTableSize,
|
||||||
m.reloads,
|
m.reloads,
|
||||||
m.reloadsFailed,
|
m.reloadsFailed,
|
||||||
m.cutoffs,
|
m.cutoffs,
|
||||||
|
|
Loading…
Reference in a new issue