/
controller_metrics.go
139 lines (133 loc) · 5.86 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
// 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"
)
var (
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{
&view.View{
Name: "fleets_replicas_count",
Measure: fleetsReplicasCountStats,
Description: "The number of replicas per fleet",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyType, keyNamespace},
},
&view.View{
Name: "fleet_autoscalers_buffer_limits",
Measure: fasBufferLimitsCountStats,
Description: "The limits of buffer based fleet autoscalers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyType, keyFleetName, keyNamespace},
},
&view.View{
Name: "fleet_autoscalers_buffer_size",
Measure: fasBufferSizeStats,
Description: "The buffer size of fleet autoscalers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyType, keyFleetName, keyNamespace},
},
&view.View{
Name: "fleet_autoscalers_current_replicas_count",
Measure: fasCurrentReplicasStats,
Description: "The current replicas count as seen by autoscalers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyFleetName, keyNamespace},
},
&view.View{
Name: "fleet_autoscalers_desired_replicas_count",
Measure: fasDesiredReplicasStats,
Description: "The desired replicas count as seen by autoscalers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyFleetName, keyNamespace},
},
&view.View{
Name: "fleet_autoscalers_able_to_scale",
Measure: fasAbleToScaleStats,
Description: "The fleet autoscaler can access the fleet to scale",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyFleetName, keyNamespace},
},
&view.View{
Name: "fleet_autoscalers_limited",
Measure: fasLimitedStats,
Description: "The fleet autoscaler is capped",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyName, keyFleetName, keyNamespace},
},
&view.View{
Name: "gameservers_count",
Measure: gameServerCountStats,
Description: "The number of gameservers",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyType, keyFleetName, keyNamespace},
},
&view.View{
Name: "gameservers_total",
Measure: gameServerTotalStats,
Description: "The total of gameservers",
Aggregation: view.Count(),
TagKeys: []tag.Key{keyType, keyFleetName, keyNamespace},
},
&view.View{
Name: "nodes_count",
Measure: nodesCountStats,
Description: "The count of nodes in the cluster",
Aggregation: view.LastValue(),
TagKeys: []tag.Key{keyEmpty},
},
&view.View{
Name: "gameservers_node_count",
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),
},
&view.View{
Name: "gameserver_state_duration",
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)
}
}