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

Commit

Permalink
Merge pull request #1746 from grafana/log-outcome-of-aggmetrics-GC
Browse files Browse the repository at this point in the history
Aggmetrics: track how long a GC() run takes and how many series deleted
  • Loading branch information
Dieterbe authored Apr 2, 2020
2 parents c3ae72d + 8fc1576 commit e718b70
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mdata/aggmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ func NewAggMetrics(store Store, cachePusher cache.CachePusher, dropFirstChunk bo
// periodically scan chunks and close any that have not received data in a while
func (ms *AggMetrics) GC() {
for {
var purged int

unix := time.Duration(time.Now().UnixNano())
diff := ms.gcInterval - (unix % ms.gcInterval)
time.Sleep(diff + time.Minute)
log.Info("checking for stale chunks that need persisting.")
now := uint32(time.Now().Unix())
log.Info("Aggmetrics: checking for stale chunks that need persisting.")
nowTime := time.Now()
now := uint32(nowTime.Unix())
chunkMinTs := now - uint32(ms.chunkMaxStale)
metricMinTs := now - uint32(ms.metricMaxStale)

Expand Down Expand Up @@ -84,6 +87,7 @@ func (ms *AggMetrics) GC() {
if stale {
log.Debugf("metric %s is stale. Purging data from memory.", key)
ms.Lock()
purged++
delete(ms.Metrics[org], key)
orgActiveMetrics.Set(float64(len(ms.Metrics[org])))
// note: this is racey. if a metric has just become unstale, it may have created a new chunk,
Expand Down Expand Up @@ -118,6 +122,8 @@ func (ms *AggMetrics) GC() {
}
ms.RUnlock()
metricsActive.Set(totalActive)

log.Infof("Aggmetrics: finished GC %s. number of purged (deleted) metrics from tank: %d", time.Since(nowTime), purged)
}
}

Expand Down

0 comments on commit e718b70

Please sign in to comment.