Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Commit 2402a57

Browse files
committed
SS PebbleDB Metrics
1 parent 7ace1a5 commit 2402a57

3 files changed

Lines changed: 420 additions & 0 deletions

File tree

common/metrics/metrics.go

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,181 @@ var (
4747
metric.WithUnit("{count}"),
4848
)),
4949
}
50+
51+
// PebbleDB State Store Metrics
52+
PebbleDBMetrics = struct {
53+
// Operation Latencies
54+
GetLatency metric.Int64Histogram
55+
ApplyChangesetLatency metric.Int64Histogram
56+
ApplyChangesetAsyncLatency metric.Int64Histogram
57+
PruneLatency metric.Float64Histogram
58+
ImportLatency metric.Float64Histogram
59+
HashComputationLatency metric.Int64Histogram
60+
BatchWriteLatency metric.Int64Histogram
61+
62+
// Database Internal Metrics
63+
CompactionCount metric.Int64Counter
64+
CompactionDuration metric.Float64Histogram
65+
CompactionBytesRead metric.Int64Counter
66+
CompactionBytesWritten metric.Int64Counter
67+
FlushCount metric.Int64Counter
68+
FlushDuration metric.Float64Histogram
69+
FlushBytesWritten metric.Int64Counter
70+
71+
// Storage Metrics
72+
SSTableCount metric.Int64Gauge
73+
SSTableTotalSize metric.Int64Gauge
74+
MemtableCount metric.Int64Gauge
75+
MemtableTotalSize metric.Int64Gauge
76+
WALSize metric.Int64Gauge
77+
78+
// Cache Metrics
79+
CacheHits metric.Int64Counter
80+
CacheMisses metric.Int64Counter
81+
CacheSize metric.Int64Gauge
82+
83+
// Operational Metrics
84+
BatchSize metric.Int64Histogram
85+
PendingChangesQueueDepth metric.Int64Gauge
86+
IteratorCount metric.Int64Gauge
87+
}{
88+
// Operation Latencies
89+
GetLatency: must(meter.Int64Histogram(
90+
"pebble_get_latency",
91+
metric.WithDescription("Time taken to get a key from PebbleDB"),
92+
metric.WithUnit("us"),
93+
)),
94+
ApplyChangesetLatency: must(meter.Int64Histogram(
95+
"pebble_apply_changeset_latency",
96+
metric.WithDescription("Time taken to apply changeset to PebbleDB"),
97+
metric.WithUnit("ms"),
98+
)),
99+
ApplyChangesetAsyncLatency: must(meter.Int64Histogram(
100+
"pebble_apply_changeset_async_latency",
101+
metric.WithDescription("Time taken to queue changeset for async write"),
102+
metric.WithUnit("us"),
103+
)),
104+
PruneLatency: must(meter.Float64Histogram(
105+
"pebble_prune_latency",
106+
metric.WithDescription("Time taken to prune old versions from PebbleDB"),
107+
metric.WithUnit("s"),
108+
)),
109+
ImportLatency: must(meter.Float64Histogram(
110+
"pebble_import_latency",
111+
metric.WithDescription("Time taken to import snapshot data to PebbleDB"),
112+
metric.WithUnit("s"),
113+
)),
114+
HashComputationLatency: must(meter.Int64Histogram(
115+
"pebble_hash_computation_latency",
116+
metric.WithDescription("Time taken to compute hash for a block range"),
117+
metric.WithUnit("ms"),
118+
)),
119+
BatchWriteLatency: must(meter.Int64Histogram(
120+
"pebble_batch_write_latency",
121+
metric.WithDescription("Time taken to write a batch to PebbleDB"),
122+
metric.WithUnit("ms"),
123+
)),
124+
125+
// Compaction Metrics
126+
CompactionCount: must(meter.Int64Counter(
127+
"pebble_compaction_count",
128+
metric.WithDescription("Total number of compactions"),
129+
metric.WithUnit("{count}"),
130+
)),
131+
CompactionDuration: must(meter.Float64Histogram(
132+
"pebble_compaction_duration",
133+
metric.WithDescription("Duration of compaction operations"),
134+
metric.WithUnit("s"),
135+
)),
136+
CompactionBytesRead: must(meter.Int64Counter(
137+
"pebble_compaction_bytes_read",
138+
metric.WithDescription("Total bytes read during compaction"),
139+
metric.WithUnit("By"),
140+
)),
141+
CompactionBytesWritten: must(meter.Int64Counter(
142+
"pebble_compaction_bytes_written",
143+
metric.WithDescription("Total bytes written during compaction"),
144+
metric.WithUnit("By"),
145+
)),
146+
147+
// Flush Metrics
148+
FlushCount: must(meter.Int64Counter(
149+
"pebble_flush_count",
150+
metric.WithDescription("Total number of memtable flushes"),
151+
metric.WithUnit("{count}"),
152+
)),
153+
FlushDuration: must(meter.Float64Histogram(
154+
"pebble_flush_duration",
155+
metric.WithDescription("Duration of memtable flush operations"),
156+
metric.WithUnit("s"),
157+
)),
158+
FlushBytesWritten: must(meter.Int64Counter(
159+
"pebble_flush_bytes_written",
160+
metric.WithDescription("Total bytes written during memtable flushes"),
161+
metric.WithUnit("By"),
162+
)),
163+
164+
// Storage Metrics
165+
SSTableCount: must(meter.Int64Gauge(
166+
"pebble_sstable_count",
167+
metric.WithDescription("Current number of SSTables"),
168+
metric.WithUnit("{count}"),
169+
)),
170+
SSTableTotalSize: must(meter.Int64Gauge(
171+
"pebble_sstable_total_size",
172+
metric.WithDescription("Total size of all SSTables"),
173+
metric.WithUnit("By"),
174+
)),
175+
MemtableCount: must(meter.Int64Gauge(
176+
"pebble_memtable_count",
177+
metric.WithDescription("Current number of memtables"),
178+
metric.WithUnit("{count}"),
179+
)),
180+
MemtableTotalSize: must(meter.Int64Gauge(
181+
"pebble_memtable_total_size",
182+
metric.WithDescription("Total size of all memtables"),
183+
metric.WithUnit("By"),
184+
)),
185+
WALSize: must(meter.Int64Gauge(
186+
"pebble_wal_size",
187+
metric.WithDescription("Current size of Write-Ahead Log"),
188+
metric.WithUnit("By"),
189+
)),
190+
191+
// Cache Metrics
192+
CacheHits: must(meter.Int64Counter(
193+
"pebble_cache_hits",
194+
metric.WithDescription("Total number of cache hits"),
195+
metric.WithUnit("{count}"),
196+
)),
197+
CacheMisses: must(meter.Int64Counter(
198+
"pebble_cache_misses",
199+
metric.WithDescription("Total number of cache misses"),
200+
metric.WithUnit("{count}"),
201+
)),
202+
CacheSize: must(meter.Int64Gauge(
203+
"pebble_cache_size",
204+
metric.WithDescription("Current cache size"),
205+
metric.WithUnit("By"),
206+
)),
207+
208+
// Operational Metrics
209+
BatchSize: must(meter.Int64Histogram(
210+
"pebble_batch_size",
211+
metric.WithDescription("Size of batches written to PebbleDB"),
212+
metric.WithUnit("By"),
213+
)),
214+
PendingChangesQueueDepth: must(meter.Int64Gauge(
215+
"pebble_pending_changes_queue_depth",
216+
metric.WithDescription("Number of pending changesets in async write queue"),
217+
metric.WithUnit("{count}"),
218+
)),
219+
IteratorCount: must(meter.Int64Gauge(
220+
"pebble_iterator_count",
221+
metric.WithDescription("Current number of active iterators"),
222+
metric.WithUnit("{count}"),
223+
)),
224+
}
50225
)
51226

52227
// must panics if err is non-nil, otherwise returns v.

ss/pebbledb/batch.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package pebbledb
22

33
import (
4+
"context"
45
"encoding/binary"
56
"fmt"
7+
"time"
68

79
"github.com/cockroachdb/pebble"
810
"github.com/sei-protocol/sei-db/common/errors"
11+
seidbmetrics "github.com/sei-protocol/sei-db/common/metrics"
912
)
1013

1114
type Batch struct {
@@ -59,7 +62,19 @@ func (b *Batch) Delete(storeKey string, key []byte) error {
5962
}
6063

6164
func (b *Batch) Write() (err error) {
65+
startTime := time.Now()
66+
batchSize := int64(b.batch.Len())
67+
6268
defer func() {
69+
ctx := context.Background()
70+
seidbmetrics.PebbleDBMetrics.BatchWriteLatency.Record(
71+
ctx,
72+
time.Since(startTime).Milliseconds(),
73+
)
74+
seidbmetrics.PebbleDBMetrics.BatchSize.Record(
75+
ctx,
76+
batchSize,
77+
)
6378
err = errors.Join(err, b.batch.Close())
6479
}()
6580

@@ -119,7 +134,19 @@ func (b *Batch) HardDelete(storeKey string, key []byte) error {
119134
}
120135

121136
func (b *RawBatch) Write() (err error) {
137+
startTime := time.Now()
138+
batchSize := int64(b.batch.Len())
139+
122140
defer func() {
141+
ctx := context.Background()
142+
seidbmetrics.PebbleDBMetrics.BatchWriteLatency.Record(
143+
ctx,
144+
time.Since(startTime).Milliseconds(),
145+
)
146+
seidbmetrics.PebbleDBMetrics.BatchSize.Record(
147+
ctx,
148+
batchSize,
149+
)
123150
err = errors.Join(err, b.batch.Close())
124151
}()
125152

0 commit comments

Comments
 (0)