diff --git a/pcp/ssh/raplcap.go b/pcp/ssh/raplcap.go deleted file mode 100644 index f5c6ceb..0000000 --- a/pcp/ssh/raplcap.go +++ /dev/null @@ -1,27 +0,0 @@ -package ssh - -import ( - "golang.org/x/crypto/ssh" - "fmt" -) - -func main() { - sshConfig := &ssh.ClientConfig{ - User: "rapl", - Auth: []ssh.AuthMethod{ - ssh.Password("pankajlikesdanceswithwolves#!@#"), - }, - } - - connection, err := ssh.Dial("tcp", "host:port", sshConfig) - if err != nil { - return nil, fmt.Errorf("Failed to dial: %s", err) - } - - session, err := connection.NewSession() - if err != nil { - return nil, fmt.Errorf("Failed to create session: %s", err) - } - - err = session.Run("sudo /misc/shared_data/rdelval1/RAPL_PKG_Throttle.py 100") -} \ No newline at end of file diff --git a/pcp/test/power.go b/pcp/test/power.go index 6b7160a..b061e07 100644 --- a/pcp/test/power.go +++ b/pcp/test/power.go @@ -109,7 +109,7 @@ func main() { fmt.Println("Index: ", i) powerIndexes = append(powerIndexes, i) indexToHost[i] = split[0] - powerAverage[split[0]] = ring.New(10) // Two PKS per node, 10 = 5 seconds tracking + powerAverage[split[0]] = ring.New(10) // Two PKGS per node, 10 = 5 seconds tracking } } @@ -152,15 +152,7 @@ func main() { log.Printf("Current Victim %s Avg. Wattage: %f", victims[0].Host, victims[0].Watts * RAPLUnits) } - /* - fmt.Printf("Second: %d\n", seconds) - for i, val := range strings.Split(scanner.Text(), ",") { - fmt.Printf("host metric: %s val: %s\n", headers[i], val) - }*/ - seconds++ - - // fmt.Println("--------------------------------") } }(logging) diff --git a/rapl/cap.go b/rapl/cap.go new file mode 100644 index 0000000..c25eb66 --- /dev/null +++ b/rapl/cap.go @@ -0,0 +1,39 @@ +package rapl + +import ( + "golang.org/x/crypto/ssh" + "github.com/pkg/errors" + "strconv" +) + +func Cap(host, username string, percentage int) (error) { + + if percentage > 100 || percentage < 0 { + return errors.New("Percentage is out of range") + } + + sshConfig := &ssh.ClientConfig{ + User: username, + Auth: []ssh.AuthMethod{ + // TODO: CHANGE and MAKE THIS USE SSH KEY BEFORE MAKING PUBLIC!!!! + ssh.Password("pankajlikesdanceswithwolves#!@#"), + }, + } + + connection, err := ssh.Dial("tcp", host+":22", sshConfig) + if err != nil { + return errors.Wrap(err, "Failed to dial") + } + + session, err := connection.NewSession() + if err != nil { + return errors.Wrap(err, "Failed to create session") + } + + err = session.Run("sudo /misc/shared_data/rdelval1/RAPL_PKG_Throttle.py " + strconv.Itoa(percentage)) + if err != nil { + return errors.Wrap(err, "Failed to run RAPL script") + } + + return nil +}