MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / startStatsLogger

Method startStatsLogger

rest/server_context.go:1783–1813  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

1781}
1782
1783func (sc *ServerContext) startStatsLogger(ctx context.Context) {
1784
1785 if sc.Config.Unsupported.StatsLogFrequency == nil || sc.Config.Unsupported.StatsLogFrequency.Value() == 0 {
1786 // don't start the stats logger when explicitly zero
1787 return
1788 }
1789
1790 interval := sc.Config.Unsupported.StatsLogFrequency
1791
1792 sc.statsContext.statsLoggingTicker = time.NewTicker(interval.Value())
1793 sc.statsContext.terminator = make(chan struct{})
1794 sc.statsContext.doneChan = make(chan struct{})
1795 go func() {
1796 defer close(sc.statsContext.doneChan)
1797 for {
1798 select {
1799 case <-sc.statsContext.statsLoggingTicker.C:
1800 err := sc.logStats(ctx)
1801 if err != nil {
1802 base.WarnfCtx(ctx, "Error logging stats: %v", err)
1803 }
1804 case <-sc.statsContext.terminator:
1805 base.DebugfCtx(ctx, base.KeyAll, "Stopping stats logging goroutine")
1806 sc.statsContext.statsLoggingTicker.Stop()
1807 return
1808 }
1809 }
1810 }()
1811 base.InfofCtx(ctx, base.KeyAll, "Logging stats with frequency: %v", interval)
1812
1813}
1814
1815func (sc *ServerContext) logStats(ctx context.Context) error {
1816

Callers 1

NewServerContextFunction · 0.95

Calls 6

logStatsMethod · 0.95
WarnfCtxFunction · 0.92
DebugfCtxFunction · 0.92
InfofCtxFunction · 0.92
StopMethod · 0.65
ValueMethod · 0.45

Tested by

no test coverage detected