Feat: metrics for head_chunks & wal folders (#12013)

Signed-off-by: ansalamdaniel <ansalam.daniel@infracloud.io>
This commit is contained in:
ansalamdaniel 2023-03-02 15:25:56 +05:30 committed by GitHub
parent d33eb3ab17
commit c1c444504e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -502,6 +502,17 @@ func newHeadMetrics(h *Head, r prometheus.Registerer) *headMetrics {
}, func() float64 { }, func() float64 {
return float64(h.iso.lastAppendID()) return float64(h.iso.lastAppendID())
}), }),
prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Name: "prometheus_tsdb_head_chunks_storage_size_bytes",
Help: "Size of the chunks_head directory.",
}, func() float64 {
val, err := h.chunkDiskMapper.Size()
if err != nil {
level.Error(h.logger).Log("msg", "Failed to calculate size of \"chunks_head\" dir",
"err", err.Error())
}
return float64(val)
}),
) )
} }
return m return m

View file

@ -199,9 +199,10 @@ type wlMetrics struct {
truncateTotal prometheus.Counter truncateTotal prometheus.Counter
currentSegment prometheus.Gauge currentSegment prometheus.Gauge
writesFailed prometheus.Counter writesFailed prometheus.Counter
walFileSize prometheus.GaugeFunc
} }
func newWLMetrics(r prometheus.Registerer) *wlMetrics { func newWLMetrics(w *WL, r prometheus.Registerer) *wlMetrics {
m := &wlMetrics{} m := &wlMetrics{}
m.fsyncDuration = prometheus.NewSummary(prometheus.SummaryOpts{ m.fsyncDuration = prometheus.NewSummary(prometheus.SummaryOpts{
@ -233,6 +234,17 @@ func newWLMetrics(r prometheus.Registerer) *wlMetrics {
Name: "writes_failed_total", Name: "writes_failed_total",
Help: "Total number of write log writes that failed.", Help: "Total number of write log writes that failed.",
}) })
m.walFileSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Name: "storage_size_bytes",
Help: "Size of the write log directory.",
}, func() float64 {
val, err := w.Size()
if err != nil {
level.Error(w.logger).Log("msg", "Failed to calculate size of \"wal\" dir",
"err", err.Error())
}
return float64(val)
})
if r != nil { if r != nil {
r.MustRegister( r.MustRegister(
@ -243,6 +255,7 @@ func newWLMetrics(r prometheus.Registerer) *wlMetrics {
m.truncateTotal, m.truncateTotal,
m.currentSegment, m.currentSegment,
m.writesFailed, m.writesFailed,
m.walFileSize,
) )
} }
@ -279,7 +292,7 @@ func NewSize(logger log.Logger, reg prometheus.Registerer, dir string, segmentSi
if filepath.Base(dir) == WblDirName { if filepath.Base(dir) == WblDirName {
prefix = "prometheus_tsdb_out_of_order_wbl_" prefix = "prometheus_tsdb_out_of_order_wbl_"
} }
w.metrics = newWLMetrics(prometheus.WrapRegistererWithPrefix(prefix, reg)) w.metrics = newWLMetrics(w, prometheus.WrapRegistererWithPrefix(prefix, reg))
_, last, err := Segments(w.Dir()) _, last, err := Segments(w.Dir())
if err != nil { if err != nil {