forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
query_service_stats.go
75 lines (70 loc) · 2.72 KB
/
query_service_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2015, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tabletserver
import (
"time"
"github.com/youtube/vitess/go/stats"
)
// QueryServiceStats contains stats that used in queryservice level.
type QueryServiceStats struct {
// MySQLStats shows the time histogram for operations spent on mysql side.
MySQLStats *stats.Timings
// QueryStats shows the time histogram for each type of queries.
QueryStats *stats.Timings
// WaitStats shows the time histogram for wait operations
WaitStats *stats.Timings
// KillStats shows number of connections being killed.
KillStats *stats.Counters
// InfoErrors shows number of various non critical errors happened.
InfoErrors *stats.Counters
// ErrorStats shows number of critial erros happened.
ErrorStats *stats.Counters
// InternalErros shows number of errors from internal components.
InternalErrors *stats.Counters
// QPSRates shows the qps.
QPSRates *stats.Rates
// ResultStats shows the histogram of number of rows returned.
ResultStats *stats.Histogram
// SpotCheckCount shows the number of spot check events happened.
SpotCheckCount *stats.Int
}
// NewQueryServiceStats returns a new QueryServiceStats instance.
func NewQueryServiceStats(statsPrefix string, enablePublishStats bool) *QueryServiceStats {
mysqlStatsName := ""
queryStatsName := ""
qpsRateName := ""
waitStatsName := ""
killStatsName := ""
infoErrorsName := ""
errorStatsName := ""
internalErrorsName := ""
resultStatsName := ""
spotCheckCountName := ""
if enablePublishStats {
mysqlStatsName = statsPrefix + "Mysql"
queryStatsName = statsPrefix + "Queries"
qpsRateName = statsPrefix + "QPS"
waitStatsName = statsPrefix + "Waits"
killStatsName = statsPrefix + "Kills"
infoErrorsName = statsPrefix + "InfoErrors"
errorStatsName = statsPrefix + "Errors"
internalErrorsName = statsPrefix + "InternalErrors"
resultStatsName = statsPrefix + "Results"
spotCheckCountName = statsPrefix + "RowcacheSpotCheckCount"
}
resultBuckets := []int64{0, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000}
queryStats := stats.NewTimings(queryStatsName)
return &QueryServiceStats{
MySQLStats: stats.NewTimings(mysqlStatsName),
QueryStats: queryStats,
WaitStats: stats.NewTimings(waitStatsName),
KillStats: stats.NewCounters(killStatsName),
InfoErrors: stats.NewCounters(infoErrorsName),
ErrorStats: stats.NewCounters(errorStatsName),
InternalErrors: stats.NewCounters(internalErrorsName),
QPSRates: stats.NewRates(qpsRateName, queryStats, 15, 60*time.Second),
ResultStats: stats.NewHistogram(resultStatsName, resultBuckets),
SpotCheckCount: stats.NewInt(spotCheckCountName),
}
}