Skip to content

Commit

Permalink
metrics: remote Keep Alive OPM metric
Browse files Browse the repository at this point in the history
  • Loading branch information
CbcWestwolf committed Dec 23, 2022
1 parent 014159d commit bd8fb7c
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 28 deletions.
1 change: 0 additions & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func RegisterMetrics() {
prometheus.MustRegister(SyncLoadHistogram)
prometheus.MustRegister(ReadStatsHistogram)
prometheus.MustRegister(JobsGauge)
prometheus.MustRegister(KeepAliveCounter)
prometheus.MustRegister(LoadPrivilegeCounter)
prometheus.MustRegister(InfoCacheCounters)
prometheus.MustRegister(LoadSchemaCounter)
Expand Down
8 changes: 0 additions & 8 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ var (
Help: "Counter of system time jumps backward.",
})

KeepAliveCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "monitor",
Name: "keep_alive_total",
Help: "Counter of TiDB keep alive.",
})

PlanCacheCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "tidb",
Expand Down
11 changes: 1 addition & 10 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,16 +788,7 @@ func setupMetrics() {
systimeErrHandler := func() {
metrics.TimeJumpBackCounter.Inc()
}
callBackCount := 0
successCallBack := func() {
callBackCount++
// It is callback by monitor per second, we increase metrics.KeepAliveCounter per 5s.
if callBackCount >= 5 {
callBackCount = 0
metrics.KeepAliveCounter.Inc()
}
}
go systimemon.StartMonitor(time.Now, systimeErrHandler, successCallBack)
go systimemon.StartMonitor(time.Now, systimeErrHandler)

pushMetric(cfg.Status.MetricsAddr, time.Duration(cfg.Status.MetricsInterval)*time.Second)
}
Expand Down
9 changes: 1 addition & 8 deletions util/systimemon/systime_mon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,16 @@ import (
)

// StartMonitor calls systimeErrHandler if system time jump backward.
func StartMonitor(now func() time.Time, systimeErrHandler func(), successCallback func()) {
func StartMonitor(now func() time.Time, systimeErrHandler func()) {
logutil.BgLogger().Info("start system time monitor")
tick := time.NewTicker(100 * time.Millisecond)
defer tick.Stop()
tickCount := 0
for {
last := now().UnixNano()
<-tick.C
if now().UnixNano() < last {
logutil.BgLogger().Error("system time jump backward", zap.Int64("last", last))
systimeErrHandler()
}
// call successCallback per second.
tickCount++
if tickCount >= 10 {
tickCount = 0
successCallback()
}
}
}
2 changes: 1 addition & 1 deletion util/systimemon/systime_mon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestSystimeMonitor(t *testing.T) {
return time.Now().Add(-2 * time.Second)
}, func() {
errTriggered.Store(true)
}, func() {})
})

require.Eventually(t, errTriggered.Load, time.Second, 10*time.Millisecond)
}

0 comments on commit bd8fb7c

Please sign in to comment.