-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodnod_client.go
58 lines (46 loc) · 1.19 KB
/
nodnod_client.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
// Example file using NodNod Client to stat a NodNod cluster.
package main
import (
"encoding/json"
"flag"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/mohabusama/nodnod/client"
"github.com/mohabusama/nodnod/stats"
"time"
)
var (
flServer = flag.String("server", "127.0.0.1:7070", "NodNod server address")
flCount = flag.Int("count", 10, "Number of requests. 0 means forever!")
)
func main() {
flag.Parse()
nodnodClient := client.NewClient(*flServer)
if err := nodnodClient.Connect(); err != nil {
log.Fatal("Failed to connect", err)
}
defer nodnodClient.Disconnect()
count := 0
for {
if allStats, err := nodnodClient.StatAll(); err != nil {
log.Error("Failed to get stats:", err)
} else {
prettyPrint(allStats)
}
count++
if *flCount > 0 && count >= *flCount {
log.Info("Reached maximum number of requests: ", count)
nodnodClient.Disconnect()
fmt.Println("Disconnected client.\nBye!")
return
}
time.Sleep(5 * time.Second)
}
}
func prettyPrint(allStats stats.Stats) {
if prettyPrint, err := json.MarshalIndent(allStats, "", " "); err == nil {
fmt.Println(string(prettyPrint))
} else {
log.Error("Failed to unmarshal response: ", err)
}
}