Skip to content

Commit

Permalink
Report head allocated memory from go runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Cherednik committed Jan 20, 2025
1 parent bbd246b commit e918173
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/aardappel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"os/signal"
"reflect"
"runtime"
"syscall"
"time"
)
Expand Down Expand Up @@ -75,6 +76,10 @@ func DoReplication(ctx context.Context, prc *processor.Processor, dstTables []*d
mon.CommitDuration(float64(stats.CommitDurationMs) / 1000)
mon.RequestSize(stats.RequestSize)
mon.QuorumWaitingDuration(float64(stats.QuorumWaitingDurationMs) / 1000)
var memStat runtime.MemStats
runtime.ReadMemStats(&memStat)
mon.HeapAllocated(memStat.HeapAlloc)

}
xlog.Info(ctx, "Replication step ok", zap.Int("modifications", stats.ModificationsCount),
zap.Float32("mps", perSecond),
Expand Down
11 changes: 11 additions & 0 deletions internal/pmon/pmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Metrics interface {
CommitDuration(s float64)
RequestSize(c int)
QuorumWaitingDuration(s float64)
HeapAllocated(b uint64)
}

type PromMon struct {
Expand All @@ -25,6 +26,7 @@ type PromMon struct {
commitLatency prometheus.Histogram
requestSize prometheus.Counter
quorumWaitingLatency prometheus.Histogram
heapAllocated prometheus.Gauge
Stop func()
}

Expand All @@ -48,11 +50,16 @@ func NewMetrics(reg *prometheus.Registry) *PromMon {
Help: "Latency of waiting quorum changes on the destination cluster (seconds).",
Buckets: prometheus.DefBuckets,
}),
heapAllocated: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "go_heap_allocated",
Help: "Size is bytes of allocated heap objects",
}),
}
reg.MustRegister(m.modificationsCount)
reg.MustRegister(m.commitLatency)
reg.MustRegister(m.requestSize)
reg.MustRegister(m.quorumWaitingLatency)
reg.MustRegister(m.heapAllocated)
return m
}

Expand Down Expand Up @@ -101,3 +108,7 @@ func (p *PromMon) RequestSize(c int) {
func (p *PromMon) QuorumWaitingDuration(s float64) {
p.quorumWaitingLatency.Observe(s)
}

func (p *PromMon) HeapAllocated(b uint64) {
p.heapAllocated.Set(float64(b))
}

0 comments on commit e918173

Please sign in to comment.