Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: add EMA cpu usage #39995

Merged
merged 8 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions metrics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"meta.go",
"metrics.go",
"owner.go",
"resourcemanager.go",
"server.go",
"session.go",
"sli.go",
Expand Down
2 changes: 2 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ func RegisterMetrics() {
prometheus.MustRegister(TTLJobStatus)
prometheus.MustRegister(TTLPhaseTime)

prometheus.MustRegister(EMACPUUsageGauge)

tikvmetrics.InitMetrics(TiDB, TiKVClient)
tikvmetrics.RegisterMetrics()
tikvmetrics.TiKVPanicCounter = PanicCounter // reset tidb metrics for tikv metrics
Expand Down
27 changes: 27 additions & 0 deletions metrics/resourcemanager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package metrics

import "github.com/prometheus/client_golang/prometheus"

var (
// EMACPUUsageGauge means exponential moving average of CPU usage
EMACPUUsageGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "tidb",
Subsystem: "rm",
Name: "ema_cpu_usage",
Help: "exponential moving average of CPU usage",
})
)
2 changes: 1 addition & 1 deletion resourcemanager/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ func (r *ResourceManager) Start() {
// Stop is to stop resource manager
func (r *ResourceManager) Stop() {
r.cpuObserver.Stop()
r.wg.Done()
r.wg.Wait()
}
1 change: 1 addition & 0 deletions util/cpu/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "github.com/pingcap/tidb/util/cpu",
visibility = ["//visibility:public"],
deps = [
"//metrics",
"//util/cgroup",
"//util/mathutil",
"@com_github_cloudfoundry_gosigar//:gosigar",
Expand Down
2 changes: 2 additions & 0 deletions util/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/cloudfoundry/gosigar"
"github.com/pingcap/log"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/util/cgroup"
"github.com/pingcap/tidb/util/mathutil"
"go.uber.org/atomic"
Expand Down Expand Up @@ -66,6 +67,7 @@ func (c *Observer) Start() {
curr := c.observe()
c.cpu.Add(curr)
cpuUsage.Store(c.cpu.Get())
metrics.EMACPUUsageGauge.Set(c.cpu.Get())
case <-c.exit:
return
}
Expand Down