Skip to content

Commit

Permalink
Merge pull request #876 from traPtitech/add-webrtc-metrics
Browse files Browse the repository at this point in the history
add traq_webrtc_using_users, traq_webrtc_using_channels metrics
  • Loading branch information
wtks authored May 1, 2020
2 parents aa80727 + a34e60e commit 62a964c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion realtime/webrtcv3/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ import (
"errors"
"github.com/gofrs/uuid"
"github.com/leandro-lugaresi/hub"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/traPtitech/traQ/event"
"sync"
)

var ErrOccupied = errors.New("connection has already existed")
var (
ErrOccupied = errors.New("connection has already existed")
webrtcUsingUsersCounter = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "traq",
Name: "webrtc_using_users",
})
webrtcUsingChannelsCounter = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "traq",
Name: "webrtc_using_channels",
})
)

// Manager WebRTCマネージャー
type Manager struct {
Expand Down Expand Up @@ -53,6 +65,7 @@ func (m *Manager) SetState(connKey string, user, channel uuid.UUID, sessions map
userID: user,
}
m.userStates[user] = us
webrtcUsingUsersCounter.Inc()
}

if us.valid() && us.channelID != channel {
Expand All @@ -66,6 +79,7 @@ func (m *Manager) SetState(connKey string, user, channel uuid.UUID, sessions map
users: map[uuid.UUID]*userState{},
}
m.channelStates[channel] = cs
webrtcUsingChannelsCounter.Inc()
}

us.sessions = sessions
Expand Down Expand Up @@ -98,10 +112,12 @@ func (m *Manager) ResetState(connKey string, user uuid.UUID) error {
}

delete(m.userStates, user)
webrtcUsingUsersCounter.Dec()
cs := m.channelStates[us.channelID]
cs.removeUser(user)
if !cs.valid() {
delete(m.channelStates, cs.channelID)
webrtcUsingChannelsCounter.Dec()
}

m.eventbus.Publish(hub.Message{
Expand Down

0 comments on commit 62a964c

Please sign in to comment.