@@ -75,7 +75,7 @@ type Database struct {
75
75
seekCompGauge metrics.Gauge // Gauge for tracking the number of table compaction caused by read opt
76
76
manualMemAllocGauge metrics.Gauge // Gauge to track the amount of memory that has been manually allocated (not a part of runtime/GC)
77
77
78
- levelsGauge [7 ]metrics.Gauge // Gauge for tracking the number of tables in levels
78
+ levelsGauge []metrics.Gauge // Gauge for tracking the number of tables in levels
79
79
80
80
quitLock sync.Mutex // Mutex protecting the quit channel access
81
81
quitChan chan chan error // Quit channel to stop the metrics collection before closing the database
@@ -146,13 +146,8 @@ func NewCustom(file string, namespace string, customize func(options *opt.Option
146
146
ldb .seekCompGauge = metrics .NewRegisteredGauge (namespace + "compact/seek" , nil )
147
147
ldb .manualMemAllocGauge = metrics .NewRegisteredGauge (namespace + "memory/manualalloc" , nil )
148
148
149
- // leveldb has only up to 7 levels
150
- for i := range ldb .levelsGauge {
151
- ldb .levelsGauge [i ] = metrics .NewRegisteredGauge (namespace + fmt .Sprintf ("tables/level%v" , i ), nil )
152
- }
153
-
154
149
// Start up the metrics gathering and return
155
- go ldb .meter (metricsGatheringInterval )
150
+ go ldb .meter (metricsGatheringInterval , namespace )
156
151
return ldb , nil
157
152
}
158
153
@@ -271,7 +266,7 @@ func (db *Database) Path() string {
271
266
272
267
// meter periodically retrieves internal leveldb counters and reports them to
273
268
// the metrics subsystem.
274
- func (db * Database ) meter (refresh time.Duration ) {
269
+ func (db * Database ) meter (refresh time.Duration , namespace string ) {
275
270
// Create the counters to store current and previous compaction values
276
271
compactions := make ([][]int64 , 2 )
277
272
for i := 0 ; i < 2 ; i ++ {
@@ -360,8 +355,11 @@ func (db *Database) meter(refresh time.Duration) {
360
355
db .nonlevel0CompGauge .Update (int64 (stats .NonLevel0Comp ))
361
356
db .seekCompGauge .Update (int64 (stats .SeekComp ))
362
357
363
- // update tables amount
364
358
for i , tables := range stats .LevelTablesCounts {
359
+ // Append metrics for additional layers
360
+ if i >= len (db .levelsGauge ) {
361
+ db .levelsGauge = append (db .levelsGauge , metrics .NewRegisteredGauge (namespace + fmt .Sprintf ("tables/level%v" , i ), nil ))
362
+ }
365
363
db .levelsGauge [i ].Update (int64 (tables ))
366
364
}
367
365
0 commit comments