mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
add metric for tsdb size retention bytes (#667)
Signed-off-by: YaoZengzeng <yaozengzeng@zju.edu.cn>
This commit is contained in:
parent
56578602ab
commit
d5b3f07043
12
db.go
12
db.go
|
@ -157,6 +157,7 @@ type dbMetrics struct {
|
|||
startTime prometheus.GaugeFunc
|
||||
tombCleanTimer prometheus.Histogram
|
||||
blocksBytes prometheus.Gauge
|
||||
maxBytes prometheus.Gauge
|
||||
sizeRetentionCount prometheus.Counter
|
||||
}
|
||||
|
||||
|
@ -227,6 +228,10 @@ func newDBMetrics(db *DB, r prometheus.Registerer) *dbMetrics {
|
|||
Name: "prometheus_tsdb_storage_blocks_bytes",
|
||||
Help: "The number of bytes that are currently used for local storage by all blocks.",
|
||||
})
|
||||
m.maxBytes = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "prometheus_tsdb_retention_limit_bytes",
|
||||
Help: "Max number of bytes to be retained in the tsdb blocks, configured 0 means disabled",
|
||||
})
|
||||
m.sizeRetentionCount = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "prometheus_tsdb_size_retentions_total",
|
||||
Help: "The number of times that blocks were deleted because the maximum number of bytes was exceeded.",
|
||||
|
@ -244,6 +249,7 @@ func newDBMetrics(db *DB, r prometheus.Registerer) *dbMetrics {
|
|||
m.startTime,
|
||||
m.tombCleanTimer,
|
||||
m.blocksBytes,
|
||||
m.maxBytes,
|
||||
m.sizeRetentionCount,
|
||||
)
|
||||
}
|
||||
|
@ -454,6 +460,12 @@ func Open(dir string, l log.Logger, r prometheus.Registerer, opts *Options) (db
|
|||
}
|
||||
db.metrics = newDBMetrics(db, r)
|
||||
|
||||
maxBytes := opts.MaxBytes
|
||||
if maxBytes < 0 {
|
||||
maxBytes = 0
|
||||
}
|
||||
db.metrics.maxBytes.Set(float64(maxBytes))
|
||||
|
||||
if !opts.NoLockfile {
|
||||
absdir, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
|
|
24
db_test.go
24
db_test.go
|
@ -1138,6 +1138,30 @@ func TestSizeRetention(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestSizeRetentionMetric(t *testing.T) {
|
||||
cases := []struct {
|
||||
maxBytes int64
|
||||
expMaxBytes int64
|
||||
}{
|
||||
{maxBytes: 1000, expMaxBytes: 1000},
|
||||
{maxBytes: 0, expMaxBytes: 0},
|
||||
{maxBytes: -1000, expMaxBytes: 0},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
db, delete := openTestDB(t, &Options{
|
||||
BlockRanges: []int64{100},
|
||||
MaxBytes: c.maxBytes,
|
||||
})
|
||||
|
||||
actMaxBytes := int64(prom_testutil.ToFloat64(db.metrics.maxBytes))
|
||||
testutil.Equals(t, actMaxBytes, c.expMaxBytes, "metric retention limit bytes mismatch")
|
||||
|
||||
testutil.Ok(t, db.Close())
|
||||
delete()
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotMatcherSelectsLabelsUnsetSeries(t *testing.T) {
|
||||
db, delete := openTestDB(t, nil)
|
||||
defer func() {
|
||||
|
|
Loading…
Reference in a new issue