Skip to content

Commit

Permalink
executor: metrics slow query is divided into internal and general (#2…
Browse files Browse the repository at this point in the history
…2350) (#22405)

Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
ti-srebot authored Jan 20, 2021
1 parent 376adca commit 3471f69
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
22 changes: 19 additions & 3 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ import (
"go.uber.org/zap/zapcore"
)

// metrics option
var (
totalQueryProcHistogramGeneral = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblGeneral)
totalCopProcHistogramGeneral = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblGeneral)
totalCopWaitHistogramGeneral = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblGeneral)
totalQueryProcHistogramInternal = metrics.TotalQueryProcHistogram.WithLabelValues(metrics.LblInternal)
totalCopProcHistogramInternal = metrics.TotalCopProcHistogram.WithLabelValues(metrics.LblInternal)
totalCopWaitHistogramInternal = metrics.TotalCopWaitHistogram.WithLabelValues(metrics.LblInternal)
)

// processinfoSetter is the interface use to set current running process info.
type processinfoSetter interface {
SetProcessInfo(string, time.Time, byte, uint64)
Expand Down Expand Up @@ -915,9 +925,15 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems))
} else {
logutil.SlowQueryLogger.Warn(sessVars.SlowLogFormat(slowItems))
metrics.TotalQueryProcHistogram.Observe(costTime.Seconds())
metrics.TotalCopProcHistogram.Observe(execDetail.ProcessTime.Seconds())
metrics.TotalCopWaitHistogram.Observe(execDetail.WaitTime.Seconds())
if sessVars.InRestrictedSQL {
totalQueryProcHistogramInternal.Observe(costTime.Seconds())
totalCopProcHistogramInternal.Observe(execDetail.ProcessTime.Seconds())
totalCopWaitHistogramInternal.Observe(execDetail.WaitTime.Seconds())
} else {
totalQueryProcHistogramGeneral.Observe(costTime.Seconds())
totalCopProcHistogramGeneral.Observe(execDetail.ProcessTime.Seconds())
totalCopWaitHistogramGeneral.Observe(execDetail.WaitTime.Seconds())
}
var userString string
if sessVars.User != nil {
userString = sessVars.User.String()
Expand Down
12 changes: 6 additions & 6 deletions metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,24 +629,24 @@
"steppedLine": false,
"targets": [
{
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_process_duration_seconds_bucket[1m])) by (le))",
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_process_duration_seconds_bucket[1m])) by (le,sql_type))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "all_proc",
"legendFormat": "all_proc_{{sql_type}}",
"refId": "A"
},
{
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_cop_duration_seconds_bucket[1m])) by (le))",
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_cop_duration_seconds_bucket[1m])) by (le,sql_type))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "all_cop_proc",
"legendFormat": "all_cop_proc_{{sql_type}}",
"refId": "B"
},
{
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_wait_duration_seconds_bucket[1m])) by (le))",
"expr": "histogram_quantile(0.90, sum(rate(tidb_server_slow_query_wait_duration_seconds_bucket[1m])) by (le,sql_type))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "all_cop_wait",
"legendFormat": "all_cop_wait_{{sql_type}}",
"refId": "C"
}
],
Expand Down
12 changes: 6 additions & 6 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,30 +129,30 @@ var (
Buckets: prometheus.ExponentialBuckets(1, 2, 30), // 1us ~ 528s
})

TotalQueryProcHistogram = prometheus.NewHistogram(
TotalQueryProcHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "slow_query_process_duration_seconds",
Help: "Bucketed histogram of processing time (s) of of slow queries.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 28), // 1ms ~ 1.5days
})
TotalCopProcHistogram = prometheus.NewHistogram(
}, []string{LblSQLType})
TotalCopProcHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "slow_query_cop_duration_seconds",
Help: "Bucketed histogram of all cop processing time (s) of of slow queries.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 28), // 1ms ~ 1.5days
})
TotalCopWaitHistogram = prometheus.NewHistogram(
}, []string{LblSQLType})
TotalCopWaitHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "slow_query_wait_duration_seconds",
Help: "Bucketed histogram of all cop waiting time (s) of of slow queries.",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 28), // 1ms ~ 1.5days
})
}, []string{LblSQLType})

MaxProcs = prometheus.NewGauge(
prometheus.GaugeOpts{
Expand Down

0 comments on commit 3471f69

Please sign in to comment.