diff --git a/enterprise/reporting/event_sampler/badger_event_sampler.go b/enterprise/reporting/event_sampler/badger_event_sampler.go index 6c74537d95..33e8c95747 100644 --- a/enterprise/reporting/event_sampler/badger_event_sampler.go +++ b/enterprise/reporting/event_sampler/badger_event_sampler.go @@ -19,10 +19,13 @@ import ( type BadgerEventSampler struct { db *badger.DB + dbPath string + module string mu sync.Mutex ttl config.ValueLoader[time.Duration] ctx context.Context cancel context.CancelFunc + logger badgerLogger wg sync.WaitGroup sc *StatsCollector } @@ -72,9 +75,12 @@ func NewBadgerEventSampler( es := &BadgerEventSampler{ db: db, + dbPath: dbPath, + module: module, ttl: ttl, ctx: ctx, cancel: cancel, + logger: badgerLogger{log}, wg: sync.WaitGroup{}, sc: NewStatsCollector(BadgerTypeEventSampler, module, stats), } @@ -152,6 +158,15 @@ func (es *BadgerEventSampler) gcLoop() { if err == nil { goto again } + + lsmSize, vlogSize, totSize, err := misc.GetBadgerDBUsage(es.dbPath) + if err != nil { + es.logger.Errorf("Error while getting %s BadgerDB usage: %v", es.module, err) + continue + } + es.sc.RecordBadgerDBSize("lsm", lsmSize) + es.sc.RecordBadgerDBSize("vlog", vlogSize) + es.sc.RecordBadgerDBSize("total", totSize) } } diff --git a/enterprise/reporting/event_sampler/stats_collector.go b/enterprise/reporting/event_sampler/stats_collector.go index 48ab49e853..e3779e4f3e 100644 --- a/enterprise/reporting/event_sampler/stats_collector.go +++ b/enterprise/reporting/event_sampler/stats_collector.go @@ -9,9 +9,11 @@ import ( const ( StatReportingEventSamplerRequestsTotal = "reporting_event_sampler_requests_total" StatReportingEventSamplerRequestDuration = "reporting_event_sampler_request_duration_seconds" + StatReportingBadgerDBSize = "reporting_badger_db_size" ) type StatsCollector struct { + module string stats stats.Stats getCounter stats.Measurement putCounter stats.Measurement @@ -24,6 +26,7 @@ func NewStatsCollector(eventSamplerType, module string, statsFactory stats.Stats putRequestTags := getTags(eventSamplerType, module, "put") return &StatsCollector{ + module: module, stats: statsFactory, getCounter: statsFactory.NewTaggedStat(StatReportingEventSamplerRequestsTotal, stats.CountType, getRequestTags), putCounter: statsFactory.NewTaggedStat(StatReportingEventSamplerRequestsTotal, stats.CountType, putRequestTags), @@ -48,6 +51,10 @@ func (sc *StatsCollector) RecordPutDuration(start time.Time) { sc.putDuration.SendTiming(time.Since(start)) } +func (sc *StatsCollector) RecordBadgerDBSize(usageType string, size int64) { + sc.stats.NewTaggedStat(StatReportingBadgerDBSize, stats.GaugeType, stats.Tags{"module": sc.module, "usageType": usageType}).Gauge(size) +} + func getTags(eventSamplerType, module, operation string) stats.Tags { return stats.Tags{"type": eventSamplerType, "module": module, "operation": operation} }