-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdashboard.go
83 lines (70 loc) · 1.78 KB
/
dashboard.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
"github.com/EverythingMe/go-disque/disque"
"github.com/garyburd/redigo/redis"
"github.com/gorilla/mux"
"github.com/skyrocknroll/disque-dashborad/utils"
"html/template"
"io"
"net/http"
)
var disquePool *disque.Pool
var t *template.Template
func init() {
var err error
disquePool = disque.NewPool(disque.DialFunc(dial), "127.0.0.1:7711")
t, err = template.ParseGlob("assets/*.html")
if err != nil {
fmt.Println(err.Error())
}
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/", index)
r.HandleFunc("/node-info", nodeInfo)
r.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(http.Dir("./assets/"))))
http.Handle("/", r)
fmt.Println("Listening on 0.0.0.0:9090")
http.ListenAndServe("0.0.0.0:9090", r)
}
func dial(addr string) (redis.Conn, error) {
return redis.Dial("tcp", addr)
}
func index(w http.ResponseWriter, r *http.Request) {
client, err := disquePool.Get()
defer client.Close()
hello, err := client.Hello()
fmt.Println(hello.NodeId)
if err != nil {
io.WriteString(w, err.Error())
}
if err != nil {
io.WriteString(w, err.Error())
}
//tdata := utils.TemplateMeta{
// "Home",
// hello,
//
//}
t.ExecuteTemplate(w, "Dashboard", hello)
//t.ExecuteTemplate(w, "layout", hello)
}
func nodeInfo(w http.ResponseWriter, r *http.Request) {
addr := r.URL.Query()["addr"][0]
client, err := redis.Dial("tcp", addr)
defer client.Close()
data, err := redis.String(client.Do("INFO"))
if err != nil {
fmt.Println(err.Error())
}
//t, err := template.ParseGlob("assets/*.html")
if err != nil {
io.WriteString(w, err.Error())
}
parsedData := utils.ParseInfoCommandResponse(data)
//io.WriteString(w, data)
t.ExecuteTemplate(w, "nodeInfo", parsedData)
}
func queueInfo(w http.ResponseWriter, r *http.Request) {
}