This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
forked from rantav/go-grpc-channelz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel-page.go
113 lines (107 loc) · 2.74 KB
/
channel-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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package channelz
import (
"context"
"fmt"
"io"
channelzgrpc "google.golang.org/grpc/channelz/grpc_channelz_v1"
log "google.golang.org/grpc/grpclog"
)
// WriteChannelPage writes an HTML document to w containing per-channel RPC stats, including a header and a footer.
func (h *grpcChannelzHandler) WriteChannelPage(w io.Writer, channel int64) {
writeHeader(w, fmt.Sprintf("ChannelZ channel %d", channel))
h.writeChannel(w, channel)
writeFooter(w)
}
func (h *grpcChannelzHandler) writeChannel(w io.Writer, channel int64) {
if err := channelTemplate.Execute(w, h.getChannel(channel)); err != nil {
log.Errorf("channelz: executing template: %v", err)
}
}
func (h *grpcChannelzHandler) getChannel(channelID int64) *channelzgrpc.GetChannelResponse {
client, err := h.connect()
if err != nil {
log.Errorf("Error creating channelz client %+v", err)
return nil
}
ctx := context.Background()
channel, err := client.GetChannel(ctx, &channelzgrpc.GetChannelRequest{ChannelId: channelID})
if err != nil {
log.Errorf("Error querying GetChannel %+v", err)
return nil
}
return channel
}
const channelTemplateHTML = `
<table frame=box cellspacing=0 cellpadding=2 class="vertical">
<tr>
<th>ChannelId</th>
<td>{{.Channel.Ref.ChannelId}}
</tr>
<tr>
<th>Channel Name</th>
<td>{{.Channel.Ref.Name}}</td>
</tr>
<tr>
<th>State</th>
<td>{{.Channel.Data.State}}</td>
</tr>
<tr>
<th>Target</th>
<td>{{.Channel.Data.Target}}</td>
</tr>
<tr>
<th>Subchannels</th>
<td>
{{range .Channel.SubchannelRef}}
<a href="{{link "subchannel" .SubchannelId}}"><b>{{.SubchannelId}}</b> {{.Name}}</a><br/>
{{end}}
</td>
</tr>
<tr>
<th>Child Channels</th>
<td>
{{range .Channel.ChannelRef}}
<a href="{{link "channel" .ChannelId}}"><b>{{.ChannelId}}</b> {{.Name}}</a><br/>
{{end}}
</td>
</tr>
<tr>
<th>Sockets</th>
<td>
{{range .Channel.SocketRef}}
<a href="{{link "socket" .SocketId}}"><b>{{.SocketId}}</b> {{.Name}}</a><br/>
{{end}}
</td>
</tr>
<tr>
<th>CreationTimestamp</th>
<td>{{.Channel.Data.Trace.CreationTimestamp | timestamp}}</td>
</tr>
<tr>
<th>CallsStarted</th>
<td>{{.Channel.Data.CallsStarted}}</td>
</tr>
<tr>
<th>CallsSucceeded</th>
<td>{{.Channel.Data.CallsSucceeded}}</td>
</tr>
<tr>
<th>CallsFailed</th>
<td>{{.Channel.Data.CallsFailed}}</td>
</tr>
<tr>
<th>LastCallStartedTimestamp</th>
<td>{{.Channel.Data.LastCallStartedTimestamp | timestamp}}</td>
</tr>
<tr>
<th>Events</th>
<td>
<pre>
{{- range .Channel.Data.Trace.Events}}
{{.Severity}} [{{.Timestamp | timestamp}}]: {{.Description}}
{{- end -}}
</pre>
</td>
</tr>
</table>
`