forked from vitessio/vitess
/
status.go
200 lines (187 loc) · 5.97 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
package main
import (
"html/template"
"github.com/youtube/vitess/go/vt/health"
"github.com/youtube/vitess/go/vt/servenv"
_ "github.com/youtube/vitess/go/vt/status"
"github.com/youtube/vitess/go/vt/tabletmanager"
"github.com/youtube/vitess/go/vt/tabletserver"
"github.com/youtube/vitess/go/vt/topo"
)
var (
// tabletTemplate contains the style sheet and the tablet itself.
tabletTemplate = `
<style>
table {
width: 100%;
border-collapse: collapse;
}
td, th {
border: 1px solid #999;
padding: 0.5rem;
}
.time {
width: 15%;
}
.healthy {
background-color: LightGreen;
}
.unhealthy {
background-color: Salmon;
}
.unhappy {
background-color: Khaki;
}
</style>
<table width="100%" border="" frame="">
<tr border="">
<td width="25%" border="">
Alias: {{github_com_youtube_vitess_vtctld_tablet .Tablet.AliasString}}<br>
Keyspace: {{github_com_youtube_vitess_vtctld_keyspace .Tablet.Keyspace}} Shard: {{github_com_youtube_vitess_vtctld_shard .Tablet.Keyspace .Tablet.Shard}} Tablet Type: {{.Tablet.Type}}<br>
SrvKeyspace: {{github_com_youtube_vitess_vtctld_srv_keyspace .Tablet.Alias.Cell .Tablet.Keyspace}}<br>
Replication graph: {{github_com_youtube_vitess_vtctld_replication .Tablet.Alias.Cell .Tablet.Keyspace .Tablet.Shard}}<br>
{{if .BlacklistedTables}}
BlacklistedTables: {{range .BlacklistedTables}}{{.}} {{end}}<br>
{{end}}
{{if .DisallowQueryService}}
Query Service disabled: {{.DisallowQueryService}}<br>
{{end}}
{{if .DisableUpdateStream}}
Update Stream disabled<br>
{{end}}
</td>
<td width="25%" border="">
<a href="/schemaz">Schema</a></br>
<a href="/debug/query_plans">Schema Query Plans</a></br>
<a href="/debug/query_stats">Schema Query Stats</a></br>
<a href="/debug/table_stats">Schema Table Stats</a></br>
</td>
<td width="25%" border="">
<a href="/queryz">Query Stats</a></br>
<a href="/debug/consolidations">Consolidations</a></br>
<a href="/querylogz">Current Query Log</a></br>
<a href="/txlogz">Current Transaction Log</a></br>
</td>
<td width="25%" border="">
<a href="/healthz">Health Check</a></br>
<a href="/debug/health">Query Service Health Check</a></br>
<a href="/streamqueryz">Current Stream Queries</a></br>
</td>
</tr>
</table>
`
// healthTemplate is just about the tablet health
healthTemplate = `
<div style="font-size: x-large">Current status: <span style="padding-left: 0.5em; padding-right: 0.5em; padding-bottom: 0.5ex; padding-top: 0.5ex;" class="{{.CurrentClass}}">{{.CurrentHTML}}</span></div>
<p>Polling health information from {{github_com_youtube_vitess_health_html_name}}. ({{.Config}})</p>
<h2>Health History</h2>
<table>
<tr>
<th class="time">Time</th>
<th>Healthcheck Result</th>
</tr>
{{range .Records}}
<tr class="{{.Class}}">
<td class="time">{{.Time.Format "Jan 2, 2006 at 15:04:05 (MST)"}}</td>
<td>{{.HTML}}</td>
</tr>
{{end}}
</table>
<dl style="font-size: small;">
<dt><span class="healthy">healthy</span></dt>
<dd>serving traffic.</dd>
<dt><span class="unhappy">unhappy</span></dt>
<dd>will serve traffic only if there are no fully healthy tablets.</dd>
<dt><span class="unhealthy">unhealthy</span></dt>
<dd>will not serve traffic.</dd>
</dl>
`
// binlogTemplate is about the binlog players
binlogTemplate = `
{{if .Controllers}}
Binlog player state: {{.State}}</br>
<table>
<tr>
<th>Index</th>
<th>SourceShard</th>
<th>State</th>
<th>StopPosition</th>
<th>LastPosition</th>
<th>SecondsBehindMaster</th>
<th>Counts</th>
<th>Rates</th>
<th>Last Error</th>
</tr>
{{range .Controllers}}
<tr>
<td>{{.Index}}</td>
<td>{{.SourceShardAsHTML}}</td>
<td>{{.State}}
{{if eq .State "Running"}}
{{if .SourceTabletAlias}}
(from {{github_com_youtube_vitess_vtctld_tablet .SourceTabletAlias}})
{{else}}
(picking source tablet)
{{end}}
{{end}}</td>
<td>{{if .StopPosition}}{{.StopPosition}}{{end}}</td>
<td>{{.LastPosition}}</td>
<td>{{.SecondsBehindMaster}}</td>
<td>{{range $key, $value := .Counts}}<b>{{$key}}</b>: {{$value}}<br>{{end}}</td>
<td>{{range $key, $values := .Rates}}<b>{{$key}}</b>: {{range $values}}{{.}} {{end}}<br>{{end}}</td>
<td>{{.LastError}}</td>
</tr>
{{end}}
</table>
{{else}}
No binlog player is running.
{{end}}
`
)
type healthStatus struct {
Records []interface{}
Config template.HTML
}
func (hs *healthStatus) CurrentClass() string {
if len(hs.Records) > 0 {
return hs.Records[0].(*tabletmanager.HealthRecord).Class()
}
return "unknown"
}
func (hs *healthStatus) CurrentHTML() template.HTML {
if len(hs.Records) > 0 {
return hs.Records[0].(*tabletmanager.HealthRecord).HTML()
}
return template.HTML("unknown")
}
func healthHTMLName() template.HTML {
return health.DefaultAggregator.HTMLName()
}
// For use by plugins which wish to avoid racing when registering status page parts.
var onStatusRegistered func()
func addStatusParts(qsc tabletserver.Controller) {
servenv.AddStatusPart("Tablet", tabletTemplate, func() interface{} {
return map[string]interface{}{
"Tablet": topo.NewTabletInfo(agent.Tablet(), -1),
"BlacklistedTables": agent.BlacklistedTables(),
"DisallowQueryService": agent.DisallowQueryService(),
"DisableUpdateStream": !agent.EnableUpdateStream(),
}
})
servenv.AddStatusFuncs(template.FuncMap{
"github_com_youtube_vitess_health_html_name": healthHTMLName,
})
servenv.AddStatusPart("Health", healthTemplate, func() interface{} {
return &healthStatus{
Records: agent.History.Records(),
Config: tabletmanager.ConfigHTML(),
}
})
qsc.AddStatusPart()
servenv.AddStatusPart("Binlog Player", binlogTemplate, func() interface{} {
return agent.BinlogPlayerMap.Status()
})
if onStatusRegistered != nil {
onStatusRegistered()
}
}