forked from vitessio/vitess
/
status.go
267 lines (242 loc) · 6.3 KB
/
status.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package main
import (
"github.com/youtube/vitess/go/vt/servenv"
_ "github.com/youtube/vitess/go/vt/status"
"github.com/youtube/vitess/go/vt/vtgate"
)
var (
topoTemplate = `
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px solid #999;
padding: 0.2rem;
}
</style>
<table>
<tr>
<th colspan="2">SrvKeyspace Names Cache</th>
</tr>
<tr>
<th>Cell</th>
<th>SrvKeyspace Names</th>
</tr>
{{range $i, $skn := .SrvKeyspaceNames}}
<tr>
<td>{{github_com_youtube_vitess_vtctld_srv_cell $skn.Cell}}</td>
<td>{{if $skn.LastError}}<b>{{$skn.LastError}}</b>{{else}}{{range $j, $value := $skn.Value}}{{github_com_youtube_vitess_vtctld_srv_keyspace $skn.Cell $value}} {{end}}{{end}}</td>
</tr>
{{end}}
</table>
<br>
<table>
<tr>
<th colspan="3">SrvKeyspace Cache</th>
</tr>
<tr>
<th>Cell</th>
<th>Keyspace</th>
<th>SrvKeyspace</th>
</tr>
{{range $i, $sk := .SrvKeyspaces}}
<tr>
<td>{{github_com_youtube_vitess_vtctld_srv_cell $sk.Cell}}</td>
<td>{{github_com_youtube_vitess_vtctld_srv_keyspace $sk.Cell $sk.Keyspace}}</td>
<td>{{if $sk.LastError}}<b>{{$sk.LastError}}</b>{{else}}{{$sk.StatusAsHTML}}{{end}}</td>
</tr>
{{end}}
</table>
`
statsTemplate = `
<style>
#stats-charts div {
display: inline-block;
}
</style>
<table id="stats-charts">
<tr>
<td><div id="qps_by_db_type"></div></td>
<td><div id="errors_by_db_type"></div></td>
</tr>
<tr>
<td><div id="qps_by_keyspace"></div></td>
<td><div id="errors_by_keyspace"></div></td>
</tr>
<tr>
<td><div id="qps_by_operation"></div></td>
<td><div id="errors_by_operation"></div></td>
</tr>
</table>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.4.0");
google.load("visualization", "1", {packages:["corechart"]});
// minutesAgo returns the a time object representing i minutes before
// d.
function minutesAgo(d, i) {
var copy = new Date(d);
copy.setMinutes(copy.getMinutes() - i);
return copy
}
// massageData takes rates from input and returns data that's suitable
// to present in a chart.
function massageData(input, now) {
delete input['All'];
var planTypes = Object.keys(input);
if (planTypes.length === 0) {
planTypes = ["All"];
input["All"] = [];
}
var data = [["Time"].concat(planTypes)];
for (var i = 0; i < 15; i++) {
var datum = [minutesAgo(now, i)];
for (var j = 0; j < planTypes.length; j++) {
if (i < input[planTypes[0]].length) {
datum.push(+input[planTypes[j]][i].toFixed(2));
} else {
datum.push(0);
}
}
data.push(datum)
}
return data
}
var updateCallbacks = [];
function drawQPSChart(elId, key, title) {
var div = $(elId).height(400).width(600).unwrap()[0]
var chart = new google.visualization.AreaChart(div);
var options = {
title: title,
focusTarget: 'category',
isStacked: true,
vAxis: {
viewWindow: {min: 0},
}
};
var redrawing = function(input_data, now) {
chart.draw(google.visualization.arrayToDataTable(massageData(input_data[key], now)), options);
}
updateCallbacks.push(redrawing)
}
function update() {
var varzData;
// If we're accessing status through a proxy that requires a URL prefix,
// add the prefix to the vars URL.
var vars_url = '/debug/vars';
var pos = window.location.pathname.lastIndexOf('/debug/status');
if (pos > 0) {
vars_url = window.location.pathname.substring(0, pos) + vars_url;
}
var up = function() {
$.getJSON(vars_url, function(d) {
for (var i = 0; i < updateCallbacks.length; i++) {
updateCallbacks[i](d, new Date());
}
});
}
up()
window.setInterval(up, 30000)
}
google.setOnLoadCallback(function() {
drawQPSChart('#qps_by_db_type', 'QPSByDbType', 'QPS by DB type');
drawQPSChart('#qps_by_keyspace', 'QPSByKeyspace', 'QPS by keyspace');
drawQPSChart('#qps_by_operation', 'QPSByOperation', 'QPS by operation');
drawQPSChart('#errors_by_db_type', 'ErrorsByDbType', 'Errors by DB type');
drawQPSChart('#errors_by_keyspace', 'ErrorsByKeyspace', 'Errors by keyspace');
drawQPSChart('#errors_by_operation', 'ErrorsByOperation', 'Errors by operation');
update();
});
</script>
`
gatewayStatusTemplate = `
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px solid #999;
padding: 0.2rem;
}
table tr:nth-child(even) {
background-color: #eee;
}
table tr:nth-child(odd) {
background-color: #fff;
}
</style>
<table>
<tr>
<th>Keyspace</th>
<th>Shard</th>
<th>TabletType</th>
<th>Address</th>
<th>Query Sent</th>
<th>Query Error</th>
<th>QPS (avg 1m)</th>
<th>Latency (ms) (avg 1m)</th>
</tr>
{{range $i, $status := .}}
<tr>
<td>{{$status.Keyspace}}</td>
<td>{{$status.Shard}}</td>
<td>{{$status.TabletType}}</td>
<td><a href="http://{{$status.Addr}}">{{$status.Name}}</a></td>
<td>{{$status.QueryCount}}</td>
<td>{{$status.QueryError}}</td>
<td>{{$status.QPS}}</td>
<td>{{$status.AvgLatency}}</td>
</tr>
{{end}}
</table>
`
healthCheckTemplate = `
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px solid #999;
padding: 0.2rem;
}
</style>
<table>
<tr>
<th colspan="5">HealthCheck Tablet Cache</th>
</tr>
<tr>
<th>Cell</th>
<th>Keyspace</th>
<th>Shard</th>
<th>TabletType</th>
<th>TabletStats</th>
</tr>
{{range $i, $ts := .}}
<tr>
<td>{{github_com_youtube_vitess_vtctld_srv_cell $ts.Cell}}</td>
<td>{{github_com_youtube_vitess_vtctld_srv_keyspace $ts.Cell $ts.Target.Keyspace}}</td>
<td>{{$ts.Target.Shard}}</td>
<td>{{$ts.Target.TabletType}}</td>
<td>{{$ts.StatusAsHTML}}</td>
</tr>
{{end}}
</table>
`
)
// For use by plugins which wish to avoid racing when registering status page parts.
var onStatusRegistered func()
func addStatusParts(vtgate *vtgate.VTGate) {
servenv.AddStatusPart("Topology Cache", topoTemplate, func() interface{} {
return resilientSrvTopoServer.CacheStatus()
})
servenv.AddStatusPart("Gateway Status", gatewayStatusTemplate, func() interface{} {
return vtgate.GetGatewayCacheStatus()
})
servenv.AddStatusPart("Health Check Cache", healthCheckTemplate, func() interface{} {
return healthCheck.CacheStatus()
})
if onStatusRegistered != nil {
onStatusRegistered()
}
}