40 Star 147 Fork 3

Gitee 极速下载/grafana

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
.hooks
conf
docker
docs
emails
examples
packaging
pkg
api
avatar
cloudwatch
dtos
live
conn.go
hub.go
stream_manager.go
pluginproxy
static
admin.go
admin_users.go
alerting.go
annotations.go
api.go
apikey.go
app_routes.go
common.go
dashboard.go
dashboard_snapshot.go
dataproxy.go
datasources.go
datasources_test.go
frontendsettings.go
grafana_com_proxy.go
http_server.go
index.go
login.go
login_oauth.go
metrics.go
org.go
org_invite.go
org_users.go
password.go
playlist.go
playlist_play.go
plugins.go
preferences.go
quota.go
render.go
route_register.go
route_register_test.go
search.go
signup.go
stars.go
user.go
user_test.go
bus
cmd
components
events
log
login
metrics
middleware
models
plugins
services
setting
social
tsdb
util
public
scripts
tasks
tests
vendor
.bowerrc
.bra.toml
.editorconfig
.gitignore
.jscs.json
.jsfmtrc
.jshintrc
CHANGELOG.md
CODE_OF_CONDUCT.md
Gruntfile.js
LICENSE.md
Makefile
NOTICE.md
README.md
ROADMAP.md
appveyor.yml
bower.json
build.go
circle.yml
karma.conf.js
latest.json
package.json
tsconfig.json
tslint.json
yarn.lock
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/grafana/grafana
克隆/下载
hub.go 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
package live
import (
"context"
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/log"
)
type hub struct {
log log.Logger
connections map[*connection]bool
streams map[string]map[*connection]bool
register chan *connection
unregister chan *connection
streamChannel chan *dtos.StreamMessage
subChannel chan *streamSubscription
}
type streamSubscription struct {
conn *connection
name string
remove bool
}
func newHub() *hub {
return &hub{
connections: make(map[*connection]bool),
streams: make(map[string]map[*connection]bool),
register: make(chan *connection),
unregister: make(chan *connection),
streamChannel: make(chan *dtos.StreamMessage),
subChannel: make(chan *streamSubscription),
log: log.New("stream.hub"),
}
}
func (h *hub) removeConnection() {
}
func (h *hub) run(ctx context.Context) {
for {
select {
case <-ctx.Done():
return
case c := <-h.register:
h.connections[c] = true
h.log.Info("New connection", "total", len(h.connections))
case c := <-h.unregister:
if _, ok := h.connections[c]; ok {
h.log.Info("Closing connection", "total", len(h.connections))
delete(h.connections, c)
close(c.send)
}
// hand stream subscriptions
case sub := <-h.subChannel:
h.log.Info("Subscribing", "channel", sub.name, "remove", sub.remove)
subscribers, exists := h.streams[sub.name]
// handle unsubscribe
if exists && sub.remove {
delete(subscribers, sub.conn)
continue
}
if !exists {
subscribers = make(map[*connection]bool)
h.streams[sub.name] = subscribers
}
subscribers[sub.conn] = true
// handle stream messages
case message := <-h.streamChannel:
subscribers, exists := h.streams[message.Stream]
if !exists || len(subscribers) == 0 {
h.log.Info("Message to stream without subscribers", "stream", message.Stream)
continue
}
messageBytes, _ := simplejson.NewFromAny(message).Encode()
for sub := range subscribers {
// check if channel is open
if _, ok := h.connections[sub]; !ok {
delete(subscribers, sub)
continue
}
select {
case sub.send <- messageBytes:
default:
close(sub.send)
delete(h.connections, sub)
delete(subscribers, sub)
}
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/grafana.git
git@gitee.com:mirrors/grafana.git
mirrors
grafana
grafana
v4.5.1

搜索帮助