-
Notifications
You must be signed in to change notification settings - Fork 3
/
servers-page.go
90 lines (82 loc) · 2.32 KB
/
servers-page.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
package channelz
import (
"context"
"io"
channelzgrpc "google.golang.org/grpc/channelz/grpc_channelz_v1"
log "google.golang.org/grpc/grpclog"
)
// writeServers writes HTML to w containing RPC servers stats.
//
// It includes neither a header nor footer, so you can embed this data in other pages.
func (h *grpcChannelzHandler) writeServers(w io.Writer) {
if err := serversTemplate.Execute(w, h.getServers()); err != nil {
log.Errorf("channelz: executing template: %v", err)
}
}
func (h *grpcChannelzHandler) getServers() *channelzgrpc.GetServersResponse {
client, err := h.connect()
if err != nil {
log.Errorf("Error creating channelz client %+v", err)
return nil
}
ctx := context.Background()
servers, err := client.GetServers(ctx, &channelzgrpc.GetServersRequest{})
if err != nil {
log.Errorf("Error querying GetServers %+v", err)
return nil
}
return servers
}
const serversTemplateHTML = `
{{define "server-header"}}
<tr classs="header">
<th>Server</th>
<th>CreationTimestamp</th>
<th>CallsStarted</th>
<th>CallsSucceeded</th>
<th>CallsFailed</th>
<th>LastCallStartedTimestamp</th>
<th>Sockets</th>
</tr>
{{end}}
{{define "server-body"}}
<tr>
<td><a href="{{link "server" .Ref.ServerId}}"><b>{{.Ref.ServerId}}</b> {{.Ref.Name}}</a></td>
<td>{{with .Data.Trace}} {{.CreationTimestamp | timestamp}} {{end}}</td>
<td>{{.Data.CallsStarted}}</td>
<td>{{.Data.CallsSucceeded}}</td>
<td>{{.Data.CallsFailed}}</td>
<td>{{.Data.LastCallStartedTimestamp | timestamp}}</td>
<td>
{{range .ListenSocket}}
<a href="{{link "socket" .SocketId}}"><b>{{.SocketId}}</b> {{.Name}}</a> <br/>
{{end}}
</td>
</tr>
{{with .Data.Trace}}
<tr classs="header">
<th colspan=100>Events</th>
</tr>
<tr>
<td> </td>
<td colspan=100>
<pre>
{{- range .Events}}
{{.Severity}} [{{.Timestamp | timestamp}}]: {{.Description}}
{{- end -}}
</pre>
</td>
</tr>
{{end}}
{{end}}
<p><table class="section-header" width=100%><tr align=center><td>Servers</td></tr></table></p>
<table frame=box cellspacing=0 cellpadding=2>
<tr class="header">
<th colspan=100 style="text-align:left">Servers: {{.Server | len}}</th>
</tr>
{{template "server-header"}}
{{range .Server}}
{{template "server-body" .}}
{{end}}
</table>
`