Skip to content

Commit

Permalink
Utilize a faster node metric query method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtpdt committed Aug 25, 2020
1 parent 01dd959 commit 1277b79
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os/exec"
"regexp"
"sort"
"strconv"
"strings"
)

Expand Down Expand Up @@ -67,7 +68,9 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {

for _, line := range lines_uniq {
if strings.Contains(line, ",") {
state := strings.Split(line, ",")[1]
split := strings.Split(line, ",")
count, _ := strconv.ParseFloat(strings.TrimSpace(split[0]), 64)
state := split[1]
alloc := regexp.MustCompile(`^alloc`)
comp := regexp.MustCompile(`^comp`)
down := regexp.MustCompile(`^down`)
Expand All @@ -80,25 +83,25 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {
resv := regexp.MustCompile(`^res`)
switch {
case alloc.MatchString(state) == true:
nm.alloc++
nm.alloc += count
case comp.MatchString(state) == true:
nm.comp++
nm.comp += count
case down.MatchString(state) == true:
nm.down++
nm.down += count
case drain.MatchString(state) == true:
nm.drain++
nm.drain += count
case fail.MatchString(state) == true:
nm.fail++
nm.fail += count
case err.MatchString(state) == true:
nm.err++
nm.err += count
case idle.MatchString(state) == true:
nm.idle++
nm.idle += count
case maint.MatchString(state) == true:
nm.maint++
nm.maint += count
case mix.MatchString(state) == true:
nm.mix++
nm.mix += count
case resv.MatchString(state) == true:
nm.resv++
nm.resv += count
}
}
}
Expand All @@ -107,7 +110,7 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {

// Execute the sinfo command and return its output
func NodesData() []byte {
cmd := exec.Command("sinfo", "-h", "-o %n,%T")
cmd := exec.Command("sinfo", "-h", "-o %D,%T")
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 1277b79

Please sign in to comment.