-
Notifications
You must be signed in to change notification settings - Fork 205
/
main.go
48 lines (38 loc) · 993 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"log"
"net/http"
"github.com/adjust/rmq/v5"
)
func main() {
connection, err := rmq.OpenConnection("handler", "tcp", "localhost:6379", 2, nil)
if err != nil {
panic(err)
}
http.Handle("/overview", NewHandler(connection))
fmt.Printf("Handler listening on http://localhost:3333/overview\n")
if err := http.ListenAndServe(":3333", nil); err != nil {
panic(err)
}
}
type Handler struct {
connection rmq.Connection
}
func NewHandler(connection rmq.Connection) *Handler {
return &Handler{connection: connection}
}
func (handler *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
layout := request.FormValue("layout")
refresh := request.FormValue("refresh")
queues, err := handler.connection.GetOpenQueues()
if err != nil {
panic(err)
}
stats, err := handler.connection.CollectStats(queues)
if err != nil {
panic(err)
}
log.Printf("queue stats\n%s", stats)
fmt.Fprint(writer, stats.GetHtml(layout, refresh))
}