forked from minostauros/cluster-smi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster-smi-node.go
53 lines (42 loc) · 1.04 KB
/
cluster-smi-node.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
package main
import (
"github.com/minostauros/cluster-smi/cluster"
"github.com/minostauros/cluster-smi/nvml"
"github.com/pebbe/zmq4"
"github.com/vmihailenco/msgpack"
"log"
"time"
)
var node cluster.Node
func main() {
// load ports and ip-address
cfg := LoadConfig()
cfg.Print()
if err := nvml.InitNVML(); err != nil {
log.Fatalf("Failed initializing NVML: %s\n", err.Error())
}
defer nvml.ShutdownNVML()
// sending messages (PUSH-PULL)
SocketAddr := "tcp://" + cfg.RouterIp + ":" + cfg.Ports.Nodes
log.Println("Now pushing to", SocketAddr)
socket, err := zmq4.NewSocket(zmq4.PUSH)
if err != nil {
panic(err)
}
defer socket.Close()
socket.Connect(SocketAddr)
node := &cluster.Node{}
InitNode(node)
log.Println("Cluster-SMI-Node is active. Press CTRL+C to shut down.")
for _ = range time.Tick(time.Duration(cfg.Tick) * time.Second) {
FetchNode(node)
// encode data
msg, err := msgpack.Marshal(&node)
if err != nil {
log.Fatal("encode error:", err)
panic(err)
}
// send data
socket.SendBytes(msg, 0)
}
}