@@ -169,12 +169,14 @@ type WAL struct {
169169 compress bool
170170 snappyBuf []byte
171171
172- fsyncDuration prometheus.Summary
173- pageFlushes prometheus.Counter
174- pageCompletions prometheus.Counter
175- truncateFail prometheus.Counter
176- truncateTotal prometheus.Counter
177- currentSegment prometheus.Gauge
172+ fsyncDuration prometheus.Summary
173+ pageFlushes prometheus.Counter
174+ pageCompletions prometheus.Counter
175+ truncateFail prometheus.Counter
176+ truncateTotal prometheus.Counter
177+ currentSegment prometheus.Gauge
178+ recordRawSize prometheus.Counter
179+ recordCompressedSize prometheus.Counter
178180}
179181
180182// New returns a new WAL over the given directory.
@@ -227,8 +229,16 @@ func NewSize(logger log.Logger, reg prometheus.Registerer, dir string, segmentSi
227229 Name : "prometheus_tsdb_wal_segment_current" ,
228230 Help : "WAL segment index that TSDB is currently writing to." ,
229231 })
232+ w .recordRawSize = prometheus .NewCounter (prometheus.CounterOpts {
233+ Name : "prometheus_tsdb_wal_raw_record_bytes_total" ,
234+ Help : "The total number of bytes received by the WAL." ,
235+ })
236+ w .recordCompressedSize = prometheus .NewCounter (prometheus.CounterOpts {
237+ Name : "prometheus_tsdb_wal_compressed_record_bytes_total" ,
238+ Help : "The total size of records after having been compressed." ,
239+ })
230240 if reg != nil {
231- reg .MustRegister (w .fsyncDuration , w .pageFlushes , w .pageCompletions , w .truncateFail , w .truncateTotal , w .currentSegment )
241+ reg .MustRegister (w .fsyncDuration , w .pageFlushes , w .pageCompletions , w .truncateFail , w .truncateTotal , w .currentSegment , w . recordRawSize , w . recordCompressedSize )
232242 }
233243
234244 _ , j , err := w .Segments ()
@@ -539,6 +549,7 @@ func (w *WAL) log(rec []byte, final bool) error {
539549 }
540550
541551 compressed := false
552+ w .recordRawSize .Add (float64 (len (rec )))
542553 if w .compress && len (rec ) > 0 {
543554 // Allow Snappy to use the full capacity of the buffer.
544555 w .snappyBuf = w .snappyBuf [:cap (w .snappyBuf )]
@@ -548,6 +559,7 @@ func (w *WAL) log(rec []byte, final bool) error {
548559 compressed = true
549560 }
550561 }
562+ w .recordCompressedSize .Add (float64 (len (rec )))
551563
552564 // Populate as many pages as necessary to fit the record.
553565 // Be careful to always do one pass to ensure we write zero-length records.
0 commit comments