-
Notifications
You must be signed in to change notification settings - Fork 3
/
server-page.go
93 lines (87 loc) · 2.25 KB
/
server-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
91
92
93
package channelz
import (
"context"
"fmt"
"io"
channelzgrpc "google.golang.org/grpc/channelz/grpc_channelz_v1"
log "google.golang.org/grpc/grpclog"
)
func (h *grpcChannelzHandler) WriteServerPage(w io.Writer, server int64) {
writeHeader(w, fmt.Sprintf("ChannelZ server %d", server))
h.writeServer(w, server)
writeFooter(w)
}
// writeServer writes HTML to w containing RPC single server stats.
//
// It includes neither a header nor footer, so you can embed this data in other pages.
func (h *grpcChannelzHandler) writeServer(w io.Writer, server int64) {
if err := serverTemplate.Execute(w, h.getServer(server)); err != nil {
log.Errorf("channelz: executing template: %v", err)
}
}
func (h *grpcChannelzHandler) getServer(serverID int64) *channelzgrpc.GetServerResponse {
client, err := h.connect()
if err != nil {
log.Errorf("Error creating channelz client %+v", err)
return nil
}
ctx := context.Background()
server, err := client.GetServer(ctx, &channelzgrpc.GetServerRequest{ServerId: serverID})
if err != nil {
log.Errorf("Error querying GetServer %+v", err)
return nil
}
return server
}
const serverTemplateHTML = `
<table frame=box cellspacing=0 cellpadding=2 class="vertical">
<tr>
<th>ServerId</th>
<td>{{.Server.Ref.ServerId}}</td>
</tr>
<tr>
<th>Server Name</th>
<td>{{.Server.Ref.Name}}</td>
</tr>
<tr>
<th>CreationTimestamp</th>
<td>{{with .Server.Data.Trace}} {{.CreationTimestamp | timestamp}} {{end}}</td>
</tr>
<tr>
<th>CallsStarted</th>
<td>{{.Server.Data.CallsStarted}}</td>
</tr>
<tr>
<th>CallsSucceeded</th>
<td>{{.Server.Data.CallsSucceeded}}</td>
</tr>
<tr>
<th>CallsFailed</th>
<td>{{.Server.Data.CallsFailed}}</td>
</tr>
<tr>
<th>LastCallStartedTimestamp</th>
<td>{{.Server.Data.LastCallStartedTimestamp | timestamp}}</td>
</tr>
<tr>
<th>Sockets</th>
<td>
{{range .Server.ListenSocket}}
<a href="{{link "socket" .SocketId}}"><b>{{.SocketId}}</b> {{.Name}}</a> <br/>
{{end}}
</td>
</tr>
{{with .Server.Data.Trace}}
<tr>
<th>Events</th>
<td>
<pre>
{{- range .Events}}
{{.Severity}} [{{.Timestamp | timestamp}}]: {{.Description}}
{{- end -}}
</pre>
</td>
</tr>
{{end}}
</table>
`