forked from PatWie/cluster-smi
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cluster-smi-local.go
69 lines (54 loc) · 1.77 KB
/
cluster-smi-local.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
package main
/*
This is simply reproducing "nvidia-smi" without networking.
*/
import (
"flag"
"github.com/minostauros/cluster-smi/cluster"
"github.com/minostauros/cluster-smi/nvml"
"log"
"time"
)
var clus cluster.Cluster
func main() {
// load ports and ip-address
cfg := LoadConfig()
showJustOnce := flag.Bool("once", false, "Show result just once")
showTimePtr := flag.Bool("t", false, "show time of events")
showExtendedPtr := flag.Bool("e", false, "extended view")
showProcessesPtr := flag.Bool("p", false, "verbose process information")
showContainerPtr := flag.Bool("c", false, "show Docker container")
showShortPtr := flag.Bool("s", false, "show result w/o command, gpu mem, and runtime")
nodeRegex := flag.String("n", ".", "match node-names with regex for display information "+
"(if not specified, all nodes will be shown)")
usernameFilter := flag.String("u", "", "show all information only for specific user")
useColor := flag.Bool("color", true, "use colored output")
flag.Parse()
if err := nvml.InitNVML(); err != nil {
log.Fatalf("Failed initializing NVML: %s\n", err.Error())
}
defer nvml.ShutdownNVML()
node := cluster.Node{}
InitNode(&node)
clus.Nodes = append(clus.Nodes, node)
log.Println("Cluster-SMI-Local is active. Press CTRL+C to shut down.")
for {
FetchNode(&clus.Nodes[0])
if *usernameFilter != "" {
clus = cluster.FilterByUser(clus, *usernameFilter)
}
clus.FilterNodes(*nodeRegex)
if *showShortPtr {
*showContainerPtr = true
}
if *showProcessesPtr {
*showContainerPtr = true
*showShortPtr = true
}
clus.Print(*showProcessesPtr, *showTimePtr, cfg.Timeout, *useColor, *showExtendedPtr, *showShortPtr, *showContainerPtr)
if *showJustOnce {
break
}
time.Sleep(time.Duration(cfg.Tick) * time.Second)
}
}