mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
UsageStats: Add connected users and client (#38811)
This commit is contained in:
@@ -47,15 +47,6 @@ var (
|
||||
loggerCF = log.New("live.centrifuge")
|
||||
)
|
||||
|
||||
func NewGrafanaLive() *GrafanaLive {
|
||||
return &GrafanaLive{
|
||||
channels: make(map[string]models.ChannelHandler),
|
||||
GrafanaScope: CoreGrafanaScope{
|
||||
Features: make(map[string]models.ChannelHandlerFactory),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// CoreGrafanaScope list of core features
|
||||
type CoreGrafanaScope struct {
|
||||
Features map[string]models.ChannelHandlerFactory
|
||||
@@ -341,6 +332,11 @@ type GrafanaLive struct {
|
||||
storage *database.Storage
|
||||
}
|
||||
|
||||
type UsageStats struct {
|
||||
NumClients int
|
||||
NumUsers int
|
||||
}
|
||||
|
||||
func (g *GrafanaLive) getStreamPlugin(pluginID string) (backend.StreamHandler, error) {
|
||||
plugin, ok := g.PluginManager.BackendPluginManager.Get(pluginID)
|
||||
if !ok {
|
||||
@@ -722,6 +718,13 @@ func (g *GrafanaLive) ClientCount(orgID int64, channel string) (int, error) {
|
||||
return len(p.Presence), nil
|
||||
}
|
||||
|
||||
func (g *GrafanaLive) UsageStats() UsageStats {
|
||||
clients := g.node.Hub().NumClients()
|
||||
users := g.node.Hub().NumUsers()
|
||||
|
||||
return UsageStats{NumClients: clients, NumUsers: users}
|
||||
}
|
||||
|
||||
func (g *GrafanaLive) HandleHTTPPublish(ctx *models.ReqContext, cmd dtos.LivePublishCmd) response.Response {
|
||||
addr, err := live.ParseChannel(cmd.Channel)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user