From 6fb9dd09f5745d5d20d2b161cb9972d224c249f0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 24 May 2019 12:34:32 +0300 Subject: [PATCH] lib/encoding: add `vm_zstd_block_{original|compressed}_bytes_total` metrics for rough estimation of block compression ratio --- lib/encoding/compress.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/encoding/compress.go b/lib/encoding/compress.go index 3761982ee..08f196500 100644 --- a/lib/encoding/compress.go +++ b/lib/encoding/compress.go @@ -1,6 +1,7 @@ package encoding import ( + "github.com/VictoriaMetrics/metrics" "github.com/valyala/gozstd" ) @@ -9,7 +10,11 @@ import ( // // The given compressLevel is used for the compression. func CompressZSTDLevel(dst, src []byte, compressLevel int) []byte { - return gozstd.CompressLevel(dst, src, compressLevel) + originalBytes.Add(len(src)) + dstLen := len(dst) + dst = gozstd.CompressLevel(dst, src, compressLevel) + compressedBytes.Add(len(dst) - dstLen) + return dst } // DecompressZSTD decompresses src, appends the result to dst and returns @@ -17,3 +22,8 @@ func CompressZSTDLevel(dst, src []byte, compressLevel int) []byte { func DecompressZSTD(dst, src []byte) ([]byte, error) { return gozstd.Decompress(dst, src) } + +var ( + originalBytes = metrics.NewCounter(`vm_zstd_block_original_bytes_total`) + compressedBytes = metrics.NewCounter(`vm_zstd_block_compressed_bytes_total`) +)