/
controller_metrics.go
176 lines (167 loc) · 7.51 KB
/
controller_metrics.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
170
171
172
173
174
175
176
// Copyright 2019 Google LLC All Rights Reserved.
//
// 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 (
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
)
const (
fleetReplicaCountName = "fleets_replicas_count"
fleetAutoscalerBufferLimitName = "fleet_autoscalers_buffer_limits"
fleetAutoscalterBufferSizeName = "fleet_autoscalers_buffer_size"
fleetAutoscalerCurrentReplicaCountName = "fleet_autoscalers_current_replicas_count"
fleetAutoscalersDesiredReplicaCountName = "fleet_autoscalers_desired_replicas_count"
fleetAutoscalersAbleToScaleName = "fleet_autoscalers_able_to_scale"
fleetAutoscalersLimitedName = "fleet_autoscalers_limited"
gameServersCountName = "gameservers_count"
gameServersTotalName = "gameservers_total"
nodeCountName = "nodes_count"
gameServersNodeCountName = "gameservers_node_count"
gameServerStateDurationName = "gameserver_state_duration"
)
var (
// fleetAutoscalerViews are metric views associated with FleetAutoscalers
fleetAutoscalerViews = []string{fleetAutoscalerBufferLimitName, fleetAutoscalterBufferSizeName, fleetAutoscalerCurrentReplicaCountName,
fleetAutoscalersDesiredReplicaCountName, fleetAutoscalersAbleToScaleName, fleetAutoscalersLimitedName}
// fleetViews are metric views associated with Fleets
fleetViews = append([]string{fleetReplicaCountName, gameServersCountName, gameServersTotalName, gameServerStateDurationName}, fleetAutoscalerViews...)
stateDurationSeconds = []float64{0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384}
fleetsReplicasCountStats = stats.Int64("fleets/replicas_count", "The count of replicas per fleet", "1")
fasBufferLimitsCountStats = stats.Int64("fas/buffer_limits", "The buffer limits of autoscalers", "1")
fasBufferSizeStats = stats.Int64("fas/buffer_size", "The buffer size value of autoscalers", "1")
fasCurrentReplicasStats = stats.Int64("fas/current_replicas_count", "The current replicas cout as seen by autoscalers", "1")
fasDesiredReplicasStats = stats.Int64("fas/desired_replicas_count", "The desired replicas cout as seen by autoscalers", "1")
fasAbleToScaleStats = stats.Int64("fas/able_to_scale", "The fleet autoscaler can access the fleet to scale (0 indicates false, 1 indicates true)", "1")
fasLimitedStats = stats.Int64("fas/limited", "The fleet autoscaler is capped (0 indicates false, 1 indicates true)", "1")
gameServerCountStats = stats.Int64("gameservers/count", "The count of gameservers", "1")
gameServerTotalStats = stats.Int64("gameservers/total", "The total of gameservers", "1")
nodesCountStats = stats.Int64("nodes/count", "The count of nodes in the cluster", "1")
gsPerNodesCountStats = stats.Int64("gameservers_node/count", "The count of gameservers per node in the cluster", "1")
gsStateDurationSec = stats.Float64("gameservers_state/duration", "The duration of gameservers to be in a particular state", stats.UnitSeconds)
stateViews = []*view.View{
{
Name: fleetReplicaCountName,
Measure: fleetsReplicasCountStats,
Description: "The number of replicas per fleet",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyType, keyNamespace},
},
{
Name: fleetAutoscalerBufferLimitName,
Measure: fasBufferLimitsCountStats,
Description: "The limits of buffer based fleet autoscalers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyType, keyFleetName, keyNamespace},
},
{
Name: fleetAutoscalterBufferSizeName,
Measure: fasBufferSizeStats,
Description: "The buffer size of fleet autoscalers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyType, keyFleetName, keyNamespace},
},
{
Name: fleetAutoscalerCurrentReplicaCountName,
Measure: fasCurrentReplicasStats,
Description: "The current replicas count as seen by autoscalers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyFleetName, keyNamespace},
},
{
Name: fleetAutoscalersDesiredReplicaCountName,
Measure: fasDesiredReplicasStats,
Description: "The desired replicas count as seen by autoscalers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyFleetName, keyNamespace},
},
{
Name: fleetAutoscalersAbleToScaleName,
Measure: fasAbleToScaleStats,
Description: "The fleet autoscaler can access the fleet to scale",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyFleetName, keyNamespace},
},
{
Name: fleetAutoscalersLimitedName,
Measure: fasLimitedStats,
Description: "The fleet autoscaler is capped",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyFleetName, keyNamespace},
},
{
Name: gameServersCountName,
Measure: gameServerCountStats,
Description: "The number of gameservers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyType, keyFleetName, keyNamespace},
},
{
Name: gameServersTotalName,
Measure: gameServerTotalStats,
Description: "The total of gameservers",
Aggregation: view.Count(),
TagKeys: []tag.Key{keyType, keyFleetName, keyNamespace},
},
{
Name: nodeCountName,
Measure: nodesCountStats,
Description: "The count of nodes in the cluster",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyEmpty},
},
{
Name: gameServersNodeCountName,
Measure: gsPerNodesCountStats,
Description: "The count of gameservers per node in the cluster",
Aggregation: view.Distribution(0.00001, 1.00001, 2.00001, 3.00001, 4.00001, 5.00001, 6.00001, 7.00001, 8.00001, 9.00001, 10.00001, 11.00001, 12.00001, 13.00001, 14.00001, 15.00001, 16.00001, 32.00001, 40.00001, 50.00001, 60.00001, 70.00001, 80.00001, 90.00001, 100.00001, 110.00001, 120.00001),
},
{
Name: gameServerStateDurationName,
Measure: gsStateDurationSec,
Description: "The time gameserver exists in the current state in seconds",
Aggregation: view.Distribution(stateDurationSeconds...),
TagKeys: []tag.Key{keyType, keyFleetName, keyNamespace},
},
}
)
// register all our state views to OpenCensus
func registerViews() {
for _, v := range stateViews {
if err := view.Register(v); err != nil {
logger.WithError(err).Error("could not register view")
}
}
}
// unregister views, this is only useful for tests as it trigger reporting.
func unRegisterViews() {
for _, v := range stateViews {
view.Unregister(v)
}
}
// resetViews resets the values of an entire view.
// Since we have no way to delete a gauge, we have to reset
// the whole thing and start from scratch.
func resetViews(names []string) {
for _, v := range stateViews {
for _, name := range names {
if v.Name == name {
view.Unregister(v)
if err := view.Register(v); err != nil {
logger.WithError(err).Error("could not register view")
}
}
}
}
}