Skip to content

Commit

Permalink
Merge branch 'cascades/framework' of https://github.com/zz-jason/tidb
Browse files Browse the repository at this point in the history
…into cascades/framework
  • Loading branch information
zz-jason committed Dec 5, 2018
2 parents 45bf31f + 4937114 commit 0d78dcf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ require (
github.com/sirupsen/logrus v1.2.0
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72
github.com/struCoder/pidusage v0.1.2
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 // indirect
github.com/twinj/uuid v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/struCoder/pidusage v0.1.2 h1:fFPTThlcWFQyizv3xKs5Lyq1lpG5lZ36arEGNhWz2Vs=
github.com/struCoder/pidusage v0.1.2/go.mod h1:pWBlW3YuSwRl6h7R5KbvA4N8oOqe9LjaKW5CwT1SPjI=
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJfDRtkanvQPiooDH8HvJ2FBh+iKT/OmiQQ=
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU=
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 h1:lYIiVDtZnyTWlNwiAxLj0bbpTcx1BWCFhXjfsvmPdNc=
Expand Down
1 change: 1 addition & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,5 @@ func RegisterMetrics() {
prometheus.MustRegister(TotalQueryProcHistogram)
prometheus.MustRegister(TotalCopProcHistogram)
prometheus.MustRegister(TotalCopWaitHistogram)
prometheus.MustRegister(CPUUsagePercentageGauge)
}
8 changes: 8 additions & 0 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ var (
Help: "Bucketed histogram of all cop waiting time (s) of of slow queries.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 22),
})

CPUUsagePercentageGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "cpu_usage",
Help: "Percentage of CPU usage.",
})
)

// ExecuteErrorToLabel converts an execute error to label.
Expand Down
10 changes: 10 additions & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/push"
log "github.com/sirupsen/logrus"
"github.com/struCoder/pidusage"
)

// Flag Names
Expand Down Expand Up @@ -484,13 +485,22 @@ func setupMetrics() {
if callBackCount >= 5 {
callBackCount = 0
metrics.KeepAliveCounter.Inc()
updateCPUUsageMetrics()
}
}
go systimemon.StartMonitor(time.Now, systimeErrHandler, sucessCallBack)

pushMetric(cfg.Status.MetricsAddr, time.Duration(cfg.Status.MetricsInterval)*time.Second)
}

func updateCPUUsageMetrics() {
sysInfo, err := pidusage.GetStat(os.Getpid())
if err != nil {
return
}
metrics.CPUUsagePercentageGauge.Set(sysInfo.CPU)
}

func setupTracing() {
tracingCfg := cfg.OpenTracing.ToTracingConfig()
tracer, _, err := tracingCfg.New("TiDB")
Expand Down

0 comments on commit 0d78dcf

Please sign in to comment.