Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rantav/go-grpc-channelz
A ChannelZ UI for gRPC in Golang
https://github.com/rantav/go-grpc-channelz
Last synced: 1 day ago
JSON representation
A ChannelZ UI for gRPC in Golang
- Host: GitHub
- URL: https://github.com/rantav/go-grpc-channelz
- Owner: rantav
- License: mit
- Created: 2019-08-29T09:08:55.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-02T17:17:34.000Z (11 months ago)
- Last Synced: 2024-08-04T04:07:00.617Z (3 months ago)
- Language: Go
- Size: 1.21 MB
- Stars: 40
- Watchers: 3
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-grpc - go-grpc-channelz - A channelz UI for Golang. Channelz is an approved and already implemented proposal describing the inner state of gRPC connections/channels. go-grpc-channelz provides a simple UI for channelz for easy diagnosis. (Language-Specific / Go)
README
# go-grpc-channelz
An in-process Channelz UI for gRPC in Golang
## What is Channelz?
Channelz is a gRPC spec for introspection into gRPC channels.
Channels in gRPC represent connections and sockets. Channelz provides introspection into the current active grpc connections, including incoming and outgoing connections.
The full spec can be found [here](https://github.com/grpc/proposal/blob/master/A14-channelz.md)## What is `go-grpc-channelz`?
`go-grpc-channelz` provides a web UI to view the current start of all gRPC channels. For each channel you'd be able to look into the remote peer, sub-channels, load balancing stategies, number of calls, socket activity and events and so on.
You install go-grpc-channelz into your service and expose it's web page and that's it. All in all, about 2-5 lines of code.
## Screenshots
![Top Channels](doc/top-channels.png)
![Channel](doc/channel.png)
![Subchannel](doc/subchannel.png)
![Socket](doc/socket.png)
![Server](doc/server.png)
## Usage
Channelz is implemented as a gRPC service. This service is turned off by by default, so you have to turn it on as so:
```go
import (
channelzservice "google.golang.org/grpc/channelz/service"
)// Register the channelz gRPC service to grpcServer so that we can query it for this service.
channelzservice.RegisterChannelzServiceToServer(grpcServer)
```In this example `grpcServer` is a grpc server that you create externally. In many cases this server already exists (you only need one) but if not then here's how to create it:
```go
import "google.golang.org/grpc"grpcServer := grpc.NewServer()
```Now you should register the channelz web handler:
```go
import channelz "github.com/rantav/go-grpc-channelz"// Register the channelz handler and mount it to /foo.
// Resources will be available at /foo/channelz
http.Handle("/", channelz.CreateHandler("/foo", grpcBindAddress))
```Where `grpcBindAddress` is the address to which `grpcServer` is bound. This could be for example `":8080"` or `"localhost:8080"` etc. This address is required because the channelz web service accesses the channelz grpc service in order to query it.
Lastly, launch that web listener in order to serve the web UI:
```go
// Listen and serve HTTP for the default serve mux
adminListener, err := net.Listen("tcp", ":8081")
if err != nil {
log.Fatal(err)
}
go http.Serve(adminListener, nil)
```Now the service will be available at `http://localhost:8081/foo/channelz`
A complete example:
```go
import (
"google.golang.org/grpc"
channelzservice "google.golang.org/grpc/channelz/service"
channelz "github.com/rantav/go-grpc-channelz"
)grpcServer := grpc.NewServer()
// Register the channelz handler
http.Handle("/", channelz.CreateHandler("/foo", grpcBindAddress))// Register the channelz gRPC service to grpcServer so that we can query it for this service.
channelzservice.RegisterChannelzServiceToServer(grpcServer)// Listen and serve HTTP for the default serve mux
adminListener, err := net.Listen("tcp", ":8081")
if err != nil {
log.Fatal(err)
}
go http.Serve(adminListener, nil)
```