-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
stats.go
169 lines (147 loc) · 5.39 KB
/
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright 2017 Google LLC
//
// 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 spanner
import (
"context"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
)
const statsPrefix = "cloud.google.com/go/spanner/"
var (
tagKeyClientID = tag.MustNewKey("client_id")
tagKeyDatabase = tag.MustNewKey("database")
tagKeyInstance = tag.MustNewKey("instance_id")
tagKeyLibVersion = tag.MustNewKey("library_version")
tagKeyType = tag.MustNewKey("type")
tagCommonKeys = []tag.Key{tagKeyClientID, tagKeyDatabase, tagKeyInstance, tagKeyLibVersion}
tagNumInUseSessions = tag.Tag{Key: tagKeyType, Value: "num_in_use_sessions"}
tagNumBeingPrepared = tag.Tag{Key: tagKeyType, Value: "num_sessions_being_prepared"}
tagNumReadSessions = tag.Tag{Key: tagKeyType, Value: "num_read_sessions"}
tagNumWriteSessions = tag.Tag{Key: tagKeyType, Value: "num_write_prepared_sessions"}
)
func recordStat(ctx context.Context, m *stats.Int64Measure, n int64) {
stats.Record(ctx, m.M(n))
}
var (
// OpenSessionCount is a measure of the number of sessions currently opened.
// It is EXPERIMENTAL and subject to change or removal without notice.
OpenSessionCount = stats.Int64(
statsPrefix+"open_session_count",
"Number of sessions currently opened",
stats.UnitDimensionless,
)
// OpenSessionCountView is a view of the last value of OpenSessionCount.
// It is EXPERIMENTAL and subject to change or removal without notice.
OpenSessionCountView = &view.View{
Measure: OpenSessionCount,
Aggregation: view.LastValue(),
TagKeys: tagCommonKeys,
}
// MaxAllowedSessionsCount is a measure of the maximum number of sessions
// allowed. Configurable by the user.
MaxAllowedSessionsCount = stats.Int64(
statsPrefix+"max_allowed_sessions",
"The maximum number of sessions allowed. Configurable by the user.",
stats.UnitDimensionless,
)
// MaxAllowedSessionsCountView is a view of the last value of
// MaxAllowedSessionsCount.
MaxAllowedSessionsCountView = &view.View{
Measure: MaxAllowedSessionsCount,
Aggregation: view.LastValue(),
TagKeys: tagCommonKeys,
}
// SessionsCount is a measure of the number of sessions in the pool
// including both in-use, idle, and being prepared.
SessionsCount = stats.Int64(
statsPrefix+"num_sessions_in_pool",
"The number of sessions currently in use.",
stats.UnitDimensionless,
)
// SessionsCountView is a view of the last value of SessionsCount.
SessionsCountView = &view.View{
Measure: SessionsCount,
Aggregation: view.LastValue(),
TagKeys: append(tagCommonKeys, tagKeyType),
}
// MaxInUseSessionsCount is a measure of the maximum number of sessions
// in use during the last 10 minute interval.
MaxInUseSessionsCount = stats.Int64(
statsPrefix+"max_in_use_sessions",
"The maximum number of sessions in use during the last 10 minute interval.",
stats.UnitDimensionless,
)
// MaxInUseSessionsCountView is a view of the last value of
// MaxInUseSessionsCount.
MaxInUseSessionsCountView = &view.View{
Measure: MaxInUseSessionsCount,
Aggregation: view.LastValue(),
TagKeys: tagCommonKeys,
}
// GetSessionTimeoutsCount is a measure of the number of get sessions
// timeouts due to pool exhaustion.
GetSessionTimeoutsCount = stats.Int64(
statsPrefix+"get_session_timeouts",
"The number of get sessions timeouts due to pool exhaustion.",
stats.UnitDimensionless,
)
// GetSessionTimeoutsCountView is a view of the last value of
// GetSessionTimeoutsCount.
GetSessionTimeoutsCountView = &view.View{
Measure: GetSessionTimeoutsCount,
Aggregation: view.Count(),
TagKeys: tagCommonKeys,
}
// AcquiredSessionsCount is the number of sessions acquired from
// the session pool.
AcquiredSessionsCount = stats.Int64(
statsPrefix+"num_acquired_sessions",
"The number of sessions acquired from the session pool.",
stats.UnitDimensionless,
)
// AcquiredSessionsCountView is a view of the last value of
// AcquiredSessionsCount.
AcquiredSessionsCountView = &view.View{
Measure: AcquiredSessionsCount,
Aggregation: view.Count(),
TagKeys: tagCommonKeys,
}
// ReleasedSessionsCount is the number of sessions released by the user
// and pool maintainer.
ReleasedSessionsCount = stats.Int64(
statsPrefix+"num_released_sessions",
"The number of sessions released by the user and pool maintainer.",
stats.UnitDimensionless,
)
// ReleasedSessionsCountView is a view of the last value of
// ReleasedSessionsCount.
ReleasedSessionsCountView = &view.View{
Measure: ReleasedSessionsCount,
Aggregation: view.Count(),
TagKeys: tagCommonKeys,
}
)
// EnableStatViews enables all views of metrics relate to session management.
func EnableStatViews() error {
return view.Register(
OpenSessionCountView,
MaxAllowedSessionsCountView,
SessionsCountView,
MaxInUseSessionsCountView,
GetSessionTimeoutsCountView,
AcquiredSessionsCountView,
ReleasedSessionsCountView,
)
}