Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
Add metrics for WAL compression
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
  • Loading branch information
csmarchbanks committed May 20, 2019
1 parent 12d9426 commit 0d2d530
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ type WAL struct {
compress bool
snappyBuf []byte

fsyncDuration prometheus.Summary
pageFlushes prometheus.Counter
pageCompletions prometheus.Counter
truncateFail prometheus.Counter
truncateTotal prometheus.Counter
currentSegment prometheus.Gauge
fsyncDuration prometheus.Summary
pageFlushes prometheus.Counter
pageCompletions prometheus.Counter
truncateFail prometheus.Counter
truncateTotal prometheus.Counter
currentSegment prometheus.Gauge
recordRawSize prometheus.Counter
recordCompressedSize prometheus.Counter
}

// New returns a new WAL over the given directory.
Expand Down Expand Up @@ -227,8 +229,16 @@ func NewSize(logger log.Logger, reg prometheus.Registerer, dir string, segmentSi
Name: "prometheus_tsdb_wal_segment_current",
Help: "WAL segment index that TSDB is currently writing to.",
})
w.recordRawSize = prometheus.NewCounter(prometheus.CounterOpts{
Name: "prometheus_tsdb_wal_raw_record_bytes_total",
Help: "The total number of bytes received by the WAL.",
})
w.recordCompressedSize = prometheus.NewCounter(prometheus.CounterOpts{
Name: "prometheus_tsdb_wal_compressed_record_bytes_total",
Help: "The total size of records after having been compressed.",
})
if reg != nil {
reg.MustRegister(w.fsyncDuration, w.pageFlushes, w.pageCompletions, w.truncateFail, w.truncateTotal, w.currentSegment)
reg.MustRegister(w.fsyncDuration, w.pageFlushes, w.pageCompletions, w.truncateFail, w.truncateTotal, w.currentSegment, w.recordRawSize, w.recordCompressedSize)
}

_, j, err := w.Segments()
Expand Down Expand Up @@ -539,6 +549,7 @@ func (w *WAL) log(rec []byte, final bool) error {
}

compressed := false
w.recordRawSize.Add(float64(len(rec)))
if w.compress && len(rec) > 0 {
// Allow Snappy to use the full capacity of the buffer.
w.snappyBuf = w.snappyBuf[:cap(w.snappyBuf)]
Expand All @@ -548,6 +559,7 @@ func (w *WAL) log(rec []byte, final bool) error {
compressed = true
}
}
w.recordCompressedSize.Add(float64(len(rec)))

// Populate as many pages as necessary to fit the record.
// Be careful to always do one pass to ensure we write zero-length records.
Expand Down

0 comments on commit 0d2d530

Please sign in to comment.