Rates API
This commit is contained in:
parent
442ba2218d
commit
41d2efea8b
12
hub/hub.go
12
hub/hub.go
|
@ -90,12 +90,9 @@ func (h *Hub) Info() map[string]map[string]int64 {
|
||||||
info := make(map[string]map[string]int64)
|
info := make(map[string]map[string]int64)
|
||||||
|
|
||||||
for queue, size := range h.storage.QueueSizes() {
|
for queue, size := range h.storage.QueueSizes() {
|
||||||
inRate, outRate := h.statistics.Rates(queue)
|
|
||||||
info[queue] = map[string]int64{
|
info[queue] = map[string]int64{
|
||||||
"messages": size,
|
"messages": size,
|
||||||
"subscriptions": 0,
|
"subscriptions": 0,
|
||||||
"in_rate": inRate,
|
|
||||||
"out_rate": outRate,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, sub := range h.subscribers {
|
for _, sub := range h.subscribers {
|
||||||
|
@ -113,13 +110,12 @@ func (h *Hub) Info() map[string]map[string]int64 {
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) RateHistory() map[string]map[string][]int64 {
|
func (h *Hub) Rates(queue string) (in, out int64) {
|
||||||
hist := map[string]map[string][]int64{}
|
return h.statistics.Rates(queue)
|
||||||
for queue, _ := range h.storage.QueueSizes() {
|
|
||||||
hist[queue] = h.statistics.RateHistory(queue)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hist
|
func (h *Hub) RateHistory(queue string) (in, out []int64) {
|
||||||
|
return h.statistics.RateHistory(queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) StorageInfo() map[string]interface{} {
|
func (h *Hub) StorageInfo() map[string]interface{} {
|
||||||
|
|
|
@ -48,9 +48,29 @@ func (s *Server) Start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) statusHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) statusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
info := s.hub.Info()
|
var (
|
||||||
jsn, _ := json.Marshal(info)
|
res = map[string]map[string]interface{}{}
|
||||||
|
info = s.hub.Info()
|
||||||
|
withRates = (r.FormValue("rates") != "")
|
||||||
|
)
|
||||||
|
|
||||||
|
for queue, meta := range info {
|
||||||
|
res[queue] = map[string]interface{}{}
|
||||||
|
|
||||||
|
for key, val := range meta {
|
||||||
|
res[queue][key] = val
|
||||||
|
}
|
||||||
|
if withRates {
|
||||||
|
inRate, outRate := s.hub.Rates(queue)
|
||||||
|
inHist, outHist := s.hub.RateHistory(queue)
|
||||||
|
res[queue]["in_rate"] = inRate
|
||||||
|
res[queue]["out_rate"] = outRate
|
||||||
|
res[queue]["in_rate_history"] = inHist
|
||||||
|
res[queue]["out_rate_history"] = outHist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jsn, _ := json.Marshal(res)
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.Write(jsn)
|
w.Write(jsn)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ type (
|
||||||
|
|
||||||
func New() *Stats {
|
func New() *Stats {
|
||||||
s := &Stats{
|
s := &Stats{
|
||||||
q: map[string]*meta{},
|
queues: map[string]*meta{},
|
||||||
}
|
}
|
||||||
|
|
||||||
go s.loopCollectSeconds()
|
go s.loopCollectSeconds()
|
||||||
|
@ -50,18 +50,16 @@ func (s *Stats) Rates(queue string) (in, out int64) {
|
||||||
return p.in, p.out
|
return p.in, p.out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stats) RateHistory(queue string) map[string][]int64 {
|
func (s *Stats) RateHistory(queue string) (in, out []int64) {
|
||||||
hist := map[string][]int64{
|
in = []int64{}
|
||||||
"in": []int64{},
|
out = []int64{}
|
||||||
"out": []int64{},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range s.metaFor(queue).points {
|
for _, p := range s.metaFor(queue).points {
|
||||||
hist["in"] = append(hist["in"], p.in)
|
in = append(in, p.in)
|
||||||
hist["out"] = append(hist["out"], p.out)
|
out = append(out, p.out)
|
||||||
}
|
}
|
||||||
|
|
||||||
return hist
|
return in, out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stats) loopCollectSeconds() {
|
func (s *Stats) loopCollectSeconds() {
|
||||||
|
|
Loading…
Reference in New Issue