Exporting Variables for Debug

The variables are

* Total Channels
* Total Subscribers
* Total of unique Messages received by the system.
This commit is contained in:
claudemiro
2015-01-12 22:41:42 -03:00
parent 71d5099ac3
commit cadc72d482
4 changed files with 37 additions and 7 deletions
+2 -2
View File
@@ -1,14 +1,14 @@
IPÊ
---
* TODO [7/14]
* TODO [8/14]
- [X] Autenticação API Rest
- [X] Autenticação Websockets
- [ ] Console de log
- [X] Ping e Pong
- [ ] Escrever testes automatizados
- [ ] SSL
- [ ] Expvar - Canais, inscritos
- [X] Expvar - Canais, inscritos
- [-] Otimizações [1/3]
- [ ] Refatorar partes do código, remover repetições
- [X] Alterar tipos de dados de slices para mapas em alguns locais.
+27 -3
View File
@@ -6,11 +6,28 @@ package main
import (
"errors"
"expvar"
"sync"
log "github.com/golang/glog"
)
var (
// Exports the quantity of subscribers
expSubscribers *expvar.Int
// Exports the quantity of channels
expChannels *expvar.Int
expMessages *expvar.Int
)
func init() {
expSubscribers = expvar.NewInt("TotalSubscribers")
expChannels = expvar.NewInt("TotalChannels")
expMessages = expvar.NewInt("TotalMessagesPublished")
}
// An App
type App struct {
sync.Mutex
@@ -94,22 +111,25 @@ func (a *App) Disconnect(socketID string) {
// Remove from app
a.Lock()
defer a.Unlock()
_, exists := a.Subscribers[s.SocketID]
if !exists {
return
}
delete(a.Subscribers, s.SocketID)
a.Unlock()
expSubscribers.Set(int64(len(a.Subscribers)))
}
// Connect a new Subscriber
func (a *App) Connect(s *Subscriber) {
log.Infof("Adding a new Subscriber %s to app %s", s.SocketID, a.Name)
a.Lock()
defer a.Unlock()
a.Subscribers[s.SocketID] = s
a.Unlock()
expSubscribers.Set(int64(len(a.Subscribers)))
}
// Find a Subscriber on this app
@@ -131,6 +151,8 @@ func (a *App) AddChannel(c *Channel) {
a.Lock()
a.Channels[c.ChannelID] = c
a.Unlock()
expChannels.Set(int64(len(a.Channels)))
}
// Returns a Channel from this app
@@ -159,6 +181,8 @@ func (a *App) FindChannelByChannelID(n string) (*Channel, error) {
}
func (a *App) Publish(c *Channel, event RawEvent, ignore string) error {
expMessages.Add(1)
return c.Publish(a, event, ignore)
}
+3 -2
View File
@@ -8,8 +8,9 @@ import "errors"
// The config file
type ConfigFile struct {
Host string // The host, eg: :8080 will start on 0.0.0.0:8080
Apps []*App
Host string // The host, eg: :8080 will start on 0.0.0.0:8080
Expvar bool
Apps []*App
}
// Error for App not found
+5
View File
@@ -5,6 +5,7 @@
package main
import (
_ "expvar"
"net/http"
"os"
@@ -17,6 +18,10 @@ import (
func NewRouter() *mux.Router {
router := mux.NewRouter().StrictSlash(true)
if Conf.Expvar {
router.Handle("/debug/vars", http.DefaultServeMux)
}
for _, route := range routes {
var handler http.Handler