Restore debug handler
This commit is contained in:
		
							parent
							
								
									2a6f063ab0
								
							
						
					
					
						commit
						8365c05961
					
				@ -62,7 +62,7 @@ func (h *Hub) Sub(s *Subscription) {
 | 
			
		||||
func (h *Hub) Info() 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{
 | 
			
		||||
			"messages":      size,
 | 
			
		||||
			"subscriptions": 0,
 | 
			
		||||
@ -83,6 +83,10 @@ func (h *Hub) Info() map[string]map[string]uint {
 | 
			
		||||
	return info
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *Hub) StorageInfo() map[string]interface{} {
 | 
			
		||||
	return h.storage.Info()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *Hub) cleanupEverySecond() {
 | 
			
		||||
	t := time.NewTicker(1 * time.Second)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								main.go
									
									
									
									
									
								
							@ -13,10 +13,6 @@ import (
 | 
			
		||||
	"github.com/KosyanMedia/burlesque/storage"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	version = "0.2.0"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	var (
 | 
			
		||||
		storagePath string
 | 
			
		||||
@ -40,7 +36,7 @@ func main() {
 | 
			
		||||
		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("Storage path: %s\n", storagePath)
 | 
			
		||||
	fmt.Printf("Server is running at http://127.0.0.1:%d\n", port)
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,7 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/KosyanMedia/burlesque/hub"
 | 
			
		||||
@ -17,6 +18,10 @@ type (
 | 
			
		||||
	}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	Version = "0.2.0"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func New(port int, h *hub.Hub) *Server {
 | 
			
		||||
	s := Server{
 | 
			
		||||
		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) {
 | 
			
		||||
	// info := make(map[string]interface{})
 | 
			
		||||
	// info["version"] = version
 | 
			
		||||
	// info["goroutines"] = runtime.NumGoroutine()
 | 
			
		||||
	info := make(map[string]interface{})
 | 
			
		||||
	info["version"] = Version
 | 
			
		||||
	info["gomaxprocs"] = runtime.GOMAXPROCS(-1)
 | 
			
		||||
	info["goroutines"] = runtime.NumGoroutine()
 | 
			
		||||
	info["kyoto_cabinet"] = s.hub.StorageInfo()
 | 
			
		||||
 | 
			
		||||
	// s, err := storage.Status()
 | 
			
		||||
	// if err != nil {
 | 
			
		||||
	// 	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)
 | 
			
		||||
	jsn, _ := json.Marshal(info)
 | 
			
		||||
	w.Write(jsn)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *Server) pubHandler(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	defer r.Body.Close()
 | 
			
		||||
	msg, _ := ioutil.ReadAll(r.Body)
 | 
			
		||||
	if len(msg) == 0 {
 | 
			
		||||
		msg = []byte(r.FormValue("msg"))
 | 
			
		||||
 | 
			
		||||
@ -78,7 +78,7 @@ func (s *Storage) Put(queue string, message []byte) (err error) {
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *Storage) Info() map[string]uint {
 | 
			
		||||
func (s *Storage) QueueSizes() map[string]uint {
 | 
			
		||||
	info := make(map[string]uint)
 | 
			
		||||
 | 
			
		||||
	for queue, c := range s.counters {
 | 
			
		||||
@ -88,6 +88,28 @@ func (s *Storage) Info() map[string]uint {
 | 
			
		||||
	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) {
 | 
			
		||||
	if err = s.kyoto.Sync(true); err != nil {
 | 
			
		||||
		return
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user