package channelz
Import Path
google.golang.org/grpc/internal/channelz (on go.dev)
Dependency Relation
imports 12 packages, and imported by 3 packages
Involved Source Files
channel.go
channelmap.go
Package channelz defines internal APIs for enabling channelz service, entry
registration/deletion, and accessing channelz data. It also defines channelz
metric struct formats.
logging.go
server.go
socket.go
subchannel.go
syscall_linux.go
trace.go
Package-Level Type Names (total 17)
Channel represents a channel within channelz, which includes metrics and
internal channelz data, such as channelz id, child list, etc.
ChannelMetrics holds connectivity state, target and call metrics for the
channel within channelz.
Entity Entity
ID is the channelz id of this channel.
Parent *Channel
RefName is the human readable reference string of this channel.
NestedChans returns a copy of the map of nested channels associated with the
Channel.
String returns a string representation of the Channel, including its parent
entity and ID.
SubChans returns a copy of the map of sub-channels associated with the
Channel.
Trace returns a copy of the Channel's trace data.
*Channel : Entity
*Channel : Identifier
*Channel : expvar.Var
*Channel : fmt.Stringer
func GetChannel(id int64) *Channel
func GetTopChannels(id int64, maxResults int) ([]*Channel, bool)
func RegisterChannel(parent *Channel, target string) *Channel
func RegisterChannel(parent *Channel, target string) *Channel
func RegisterSubChannel(parent *Channel, ref string) *SubChannel
ChannelMetrics holds connectivity state, target and call metrics for the
channel within channelz.
The number of calls that have a completed with a non-OK status.
The number of calls started on the channel.
The number of calls that have completed with an OK status.
The last time a call was started on the channel.
The current connectivity state of the channel.
The target this channel originally tried to connect to. May be absent
CopyFrom copies the metrics in o to c. For testing only.
Equal returns true iff the metrics of c are the same as the metrics of o.
For testing only.
String returns a string representation of the ChannelMetrics, including its
state, target, and call metrics.
*ChannelMetrics : expvar.Var
*ChannelMetrics : fmt.Stringer
func NewChannelMetricForTesting(state connectivity.State, target string, started, succeeded, failed, timestamp int64) *ChannelMetrics
func (*ChannelMetrics).CopyFrom(o *ChannelMetrics)
ChannelTrace provides tracing information for a channel.
It tracks various events and metadata related to the channel's lifecycle
and operations.
The time when the trace was created.
A counter for the number of events recorded in the
trace.
A slice of traceEvent pointers representing the events recorded for
this channel.
func (*Channel).Trace() *ChannelTrace
func (*SubChannel).Trace() *ChannelTrace
Entity is implemented by all channelz types.
( Entity) String() string
*Channel
Identifier (interface)
*Server
*Socket
*SubChannel
Entity : expvar.Var
Entity : fmt.Stringer
func AddTraceEvent(l grpclog.DepthLoggerV2, e Entity, depth int, desc *TraceEvent)
func Error(l grpclog.DepthLoggerV2, e Entity, args ...any)
func Errorf(l grpclog.DepthLoggerV2, e Entity, format string, args ...any)
func Info(l grpclog.DepthLoggerV2, e Entity, args ...any)
func Infof(l grpclog.DepthLoggerV2, e Entity, format string, args ...any)
func Warning(l grpclog.DepthLoggerV2, e Entity, args ...any)
func Warningf(l grpclog.DepthLoggerV2, e Entity, format string, args ...any)
EphemeralSocketMetrics are metrics that change rapidly and are tracked
outside of channelz.
The amount of window, granted to the local endpoint by the remote endpoint.
This may be slightly out of date due to network latency. This does NOT
include stream level or TCP level flow control info.
The amount of window, granted to the remote endpoint by the local endpoint.
This may be slightly out of date due to network latency. This does NOT
include stream level or TCP level flow control info.
Identifier is an opaque channelz identifier used to expose channelz symbols
outside of grpc. Currently only implemented by Channel since no other
types require exposure outside grpc.
( Identifier) String() string
*Channel
Identifier : Entity
Identifier : expvar.Var
Identifier : fmt.Stringer
IDGenerator is an incrementing atomic that tracks IDs for channelz entities.
Reset resets the generated ID back to zero. Should only be used at
initialization or by tests sensitive to the ID number.
var IDGen
RefChannelType is the type of the entity being referenced in a trace event.
String returns a string representation of the RefChannelType
RefChannelType : expvar.Var
RefChannelType : fmt.Stringer
const RefChannel
const RefListenSocket
const RefNormalSocket
const RefServer
const RefSubChannel
const RefUnknown
Server is the channelz representation of a server.
Entity Entity
ID int64
RefName string
ServerMetrics ServerMetrics
ListenSockets returns the listening sockets for s.
String returns a printable description of s.
*Server : Entity
*Server : expvar.Var
*Server : fmt.Stringer
func GetServer(id int64) *Server
func GetServers(id int64, maxResults int) ([]*Server, bool)
func RegisterServer(ref string) *Server
ServerMetrics defines a struct containing metrics for servers.
The number of incoming calls that have a completed with a non-OK status.
The number of incoming calls started on the server.
The number of incoming calls that have completed with an OK status.
The last time a call was started on the server.
CopyFrom copies the metrics data from the provided ServerMetrics
instance into the current instance.
func NewServerMetricsForTesting(started, succeeded, failed, timestamp int64) *ServerMetrics
func (*ServerMetrics).CopyFrom(o *ServerMetrics)
Severity is the severity level of a trace event.
The canonical enumeration of all valid values is here:
https://github.com/grpc/grpc-proto/blob/9b13d199cc0d4703c7ea26c9c330ba695866eb23/grpc/channelz/v1/channelz.proto#L126.
const CtError
const CtInfo
const CtUnknown
const CtWarning
Socket represents a socket within channelz which includes socket
metrics and data related to socket activity and provides methods
for managing and interacting with sockets.
Entity Entity
EphemeralMetrics func() *EphemeralSocketMetrics
ID int64
The locally bound address. Immutable.
Parent Entity
RefName string
The remote bound address. May be absent. Immutable.
Optional, represents the name of the remote endpoint, if different than
the original target name. Immutable.
Immutable.
SocketMetrics SocketMetrics
Immutable.
SocketType SocketType
String returns a string representation of the Socket, including its parent
entity, socket type, and ID.
*Socket : Entity
*Socket : expvar.Var
*Socket : fmt.Stringer
func GetServerSockets(id int64, startID int64, maxResults int) ([]*Socket, bool)
func GetSocket(id int64) *Socket
func RegisterSocket(skt *Socket) *Socket
func RegisterSocket(skt *Socket) *Socket
SocketMetrics defines the struct that the implementor of Socket interface
should return from ChannelzMetric().
The number of keep alives sent. This is typically implemented with HTTP/2
ping messages.
The last time a stream was created by this endpoint. Usually unset for
servers.
The last time a message was received by this endpoint.
The last time a message was sent by this endpoint.
The last time a stream was created by the remote endpoint. Usually unset
for clients.
MessagesReceived atomic.Int64
The number of messages successfully sent on this socket.
The number of streams that have ended unsuccessfully:
On client side, termination without receiving frame with eos bit set.
On server side, termination without sending frame with eos bit set.
The number of streams that have been started.
The number of streams that have ended successfully:
On client side, receiving frame with eos bit set.
On server side, sending frame with eos bit set.
SocketOptionData defines the struct to hold socket option data, and related
getter function to obtain info from fd.
Linger *unix.Linger
RecvTimeout *unix.Timeval
SendTimeout *unix.Timeval
TCPInfo *unix.TCPInfo
Getsockopt defines the function to get socket options requested by channelz.
It is to be passed to syscall.RawConn.Control().
func GetSocketOption(socket any) *SocketOptionData
SocketType represents the type of socket.
SubChannel is the channelz representation of a subchannel.
ChannelMetrics ChannelMetrics
Entity Entity
ID is the channelz id of this subchannel.
RefName is the human readable reference string of this subchannel.
Sockets returns a copy of the sockets map associated with the SubChannel.
(*SubChannel) String() string
Trace returns a copy of the ChannelTrace associated with the SubChannel.
*SubChannel : Entity
*SubChannel : expvar.Var
*SubChannel : fmt.Stringer
func GetSubChannel(id int64) *SubChannel
func RegisterSubChannel(parent *Channel, ref string) *SubChannel
TraceEvent is what the caller of AddTraceEvent should provide to describe the
event to be added to the channel trace.
The Parent field is optional. It is used for an event that will be recorded
in the entity's parent trace.
Desc string
Parent *TraceEvent
Severity Severity
func AddTraceEvent(l grpclog.DepthLoggerV2, e Entity, depth int, desc *TraceEvent)
Package-Level Functions (total 26)
AddTraceEvent adds trace related to the entity with specified id, using the
provided TraceEventDesc.
If channelz is not turned ON, this will simply log the event descriptions.
Error logs and adds a trace event if channelz is on.
Errorf logs and adds a trace event if channelz is on.
GetChannel returns the Channel for the channel (identified by id).
GetServer returns the ServerMetric for the server (identified by id).
GetServers returns a slice of server's ServerMetric, along with a
boolean indicating whether there's more servers to be queried for.
The arg id specifies that only server with id at or above it will be included
in the result. The returned slice is up to a length of the arg maxResults or
EntriesPerPage if maxResults is zero, and is sorted in ascending id order.
GetServerSockets returns a slice of server's (identified by id) normal socket's
SocketMetrics, along with a boolean indicating whether there's more sockets to
be queried for.
The arg startID specifies that only sockets with id at or above it will be
included in the result. The returned slice is up to a length of the arg maxResults
or EntriesPerPage if maxResults is zero, and is sorted in ascending id order.
GetSocket returns the Socket for the socket (identified by id).
GetSocketOption gets the socket option info of the conn.
GetSubChannel returns the SubChannel for the subchannel (identified by id).
GetTopChannels returns a slice of top channel's ChannelMetric, along with a
boolean indicating whether there's more top channels to be queried for.
The arg id specifies that only top channel with id at or above it will be
included in the result. The returned slice is up to a length of the arg
maxResults or EntriesPerPage if maxResults is zero, and is sorted in ascending
id order.
Info logs and adds a trace event if channelz is on.
Infof logs and adds a trace event if channelz is on.
IsOn returns whether channelz data collection is on.
NewChannelMetricForTesting creates a new instance of ChannelMetrics with
specified initial values for testing purposes.
NewServerMetricsForTesting returns an initialized ServerMetrics.
RegisterChannel registers the given channel c in the channelz database with
target as its target and reference name, and adds it to the child list of its
parent. parent == nil means no parent.
Returns a unique channelz identifier assigned to this channel.
If channelz is not turned ON, the channelz database is not mutated.
RegisterServer registers the given server s in channelz database. It returns
the unique channelz tracking id assigned to this server.
If channelz is not turned ON, the channelz database is not mutated.
RegisterSocket registers the given normal socket s in channelz database
with ref as its reference name, and adds it to the child list of its parent
(identified by skt.Parent, which must be set). It returns the unique channelz
tracking id assigned to this normal socket.
If channelz is not turned ON, the channelz database is not mutated.
RegisterSubChannel registers the given subChannel c in the channelz database
with ref as its reference name, and adds it to the child list of its parent
(identified by pid).
Returns a unique channelz identifier assigned to this subChannel.
If channelz is not turned ON, the channelz database is not mutated.
RemoveEntry removes an entry with unique channelz tracking id to be id from
channelz database.
If channelz is not turned ON, this function is a no-op.
ResetMaxTraceEntryToDefault resets the maximum number of trace entries per
entity to default.
SetMaxTraceEntry sets maximum number of trace entries per entity (i.e.
channel/subchannel). Setting it to 0 will disable channel tracing.
TurnOn turns on channelz data collection.
Warning logs and adds a trace event if channelz is on.
Warningf logs and adds a trace event if channelz is on.
Package-Level Variables (total 2)
EntriesPerPage defines the number of channelz entries to be shown on a web page.
IDGen is the global channelz entity ID generator. It should not be used
outside this package except by tests.
Package-Level Constants (total 12)
CtError indicates error level severity of a trace event.
CtInfo indicates info level severity of a trace event.
CtUnknown indicates unknown severity of a trace event.
CtWarning indicates warning level severity of a trace event.
RefChannel indicates the referenced entity is a Channel.
RefListenSocket indicates the referenced entity is a ListenSocket.
RefNormalSocket indicates the referenced entity is a NormalSocket.
RefServer indicates the referenced entity is a Server.
RefSubChannel indicates the referenced entity is a SubChannel.
RefUnknown indicates an unknown entity type, the zero value for this type.
SocketType can be one of these.
SocketType can be one of these.
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |