UsageStats: Add connected users and client (#38811)

This commit is contained in:
Torkel Ödegaard
2021-09-07 18:50:28 +02:00
committed by GitHub
parent b24a4630a6
commit 51776e6bd3
4 changed files with 86 additions and 11 deletions
+12 -9
View File
@@ -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 {