1
0
Fork 0

Restore debug handler

This commit is contained in:
Gregory Eremin 2014-09-24 14:13:08 +04:00
parent 2a6f063ab0
commit 8365c05961
4 changed files with 41 additions and 32 deletions

View File

@ -62,7 +62,7 @@ func (h *Hub) Sub(s *Subscription) {
func (h *Hub) Info() map[string]map[string]uint { func (h *Hub) Info() map[string]map[string]uint {
info := make(map[string]map[string]uint) info := make(map[string]map[string]uint)
for queue, size := range h.storage.Info() { for queue, size := range h.storage.QueueSizes() {
info[queue] = map[string]uint{ info[queue] = map[string]uint{
"messages": size, "messages": size,
"subscriptions": 0, "subscriptions": 0,
@ -83,6 +83,10 @@ func (h *Hub) Info() map[string]map[string]uint {
return info return info
} }
func (h *Hub) StorageInfo() map[string]interface{} {
return h.storage.Info()
}
func (h *Hub) cleanupEverySecond() { func (h *Hub) cleanupEverySecond() {
t := time.NewTicker(1 * time.Second) t := time.NewTicker(1 * time.Second)

View File

@ -13,10 +13,6 @@ import (
"github.com/KosyanMedia/burlesque/storage" "github.com/KosyanMedia/burlesque/storage"
) )
const (
version = "0.2.0"
)
func main() { func main() {
var ( var (
storagePath string storagePath string
@ -40,7 +36,7 @@ func main() {
os.Exit(0) os.Exit(0)
}() }()
fmt.Printf("Burlesque v%s started\n", version) fmt.Printf("Burlesque v%s started\n", server.Version)
fmt.Printf("GOMAXPROCS is set to %d\n", runtime.GOMAXPROCS(-1)) fmt.Printf("GOMAXPROCS is set to %d\n", runtime.GOMAXPROCS(-1))
fmt.Printf("Storage path: %s\n", storagePath) fmt.Printf("Storage path: %s\n", storagePath)
fmt.Printf("Server is running at http://127.0.0.1:%d\n", port) fmt.Printf("Server is running at http://127.0.0.1:%d\n", port)

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"runtime"
"strings" "strings"
"github.com/KosyanMedia/burlesque/hub" "github.com/KosyanMedia/burlesque/hub"
@ -17,6 +18,10 @@ type (
} }
) )
const (
Version = "0.2.0"
)
func New(port int, h *hub.Hub) *Server { func New(port int, h *hub.Hub) *Server {
s := Server{ s := Server{
port: port, port: port,
@ -45,35 +50,17 @@ func (s *Server) statusHandler(w http.ResponseWriter, r *http.Request) {
} }
func (s *Server) debugHandler(w http.ResponseWriter, r *http.Request) { func (s *Server) debugHandler(w http.ResponseWriter, r *http.Request) {
// info := make(map[string]interface{}) info := make(map[string]interface{})
// info["version"] = version info["version"] = Version
// info["goroutines"] = runtime.NumGoroutine() info["gomaxprocs"] = runtime.GOMAXPROCS(-1)
info["goroutines"] = runtime.NumGoroutine()
info["kyoto_cabinet"] = s.hub.StorageInfo()
// s, err := storage.Status() jsn, _ := json.Marshal(info)
// if err != nil { w.Write(jsn)
// alert(err, "Failed to get Kyoto Cabinet status")
// }
// s = s[:len(s)-1] // Removing trailing new line
// ks := make(map[string]interface{})
// tokens := strings.Split(s, "\n")
// for _, t := range tokens {
// tt := strings.Split(t, "\t")
// num, err := strconv.Atoi(tt[1])
// if err != nil {
// ks[tt[0]] = tt[1]
// } else {
// ks[tt[0]] = num
// }
// }
// info["kyoto_cabinet"] = ks
// jsn, _ := json.Marshal(info)
// w.Write(jsn)
} }
func (s *Server) pubHandler(w http.ResponseWriter, r *http.Request) { func (s *Server) pubHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
msg, _ := ioutil.ReadAll(r.Body) msg, _ := ioutil.ReadAll(r.Body)
if len(msg) == 0 { if len(msg) == 0 {
msg = []byte(r.FormValue("msg")) msg = []byte(r.FormValue("msg"))

View File

@ -78,7 +78,7 @@ func (s *Storage) Put(queue string, message []byte) (err error) {
return return
} }
func (s *Storage) Info() map[string]uint { func (s *Storage) QueueSizes() map[string]uint {
info := make(map[string]uint) info := make(map[string]uint)
for queue, c := range s.counters { for queue, c := range s.counters {
@ -88,6 +88,28 @@ func (s *Storage) Info() map[string]uint {
return info return info
} }
func (s *Storage) Info() map[string]interface{} {
info := make(map[string]interface{})
status, err := s.kyoto.Status()
if err != nil {
panic(err)
}
status = status[:len(status)-1] // Removing trailing new line
tokens := strings.Split(status, "\n")
for _, t := range tokens {
tt := strings.Split(t, "\t")
num, err := strconv.Atoi(tt[1])
if err != nil {
info[tt[0]] = tt[1]
} else {
info[tt[0]] = num
}
}
return info
}
func (s *Storage) Close() (err error) { func (s *Storage) Close() (err error) {
if err = s.kyoto.Sync(true); err != nil { if err = s.kyoto.Sync(true); err != nil {
return return