PCP code is now able to deal with receiving information asynchronously from pmdumptext

This commit is contained in:
Renan DelValle 2016-09-22 18:34:05 -04:00
parent 992455048a
commit 58c6bfe7a8
3 changed files with 57 additions and 27 deletions

1
metrics.go Normal file
View file

@ -0,0 +1 @@
package electron

27
pcp.go
View file

@ -1,27 +0,0 @@
package main
import (
"fmt"
"log"
"os"
"os/exec"
"time"
)
func PCP() {
cmd := exec.Command("sh", "-c", "pmdumptext -m -l -o -d , -c config")
time := time.Now().Format("200601021504")
stdout, err := os.Create("./"+time+".txt")
cmd.Stdout = stdout
fmt.Println("PCP started: ")
if err != nil {
log.Fatal(err)
}
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
if err := cmd.Wait(); err != nil {
log.Fatal(err)
}
}

56
pcp/pcp.go Normal file
View file

@ -0,0 +1,56 @@
package main
import (
"fmt"
"log"
"os/exec"
"bufio"
"strings"
)
func main() {
const pcpCommand string = "pmdumptext -m -l -f '' -t 1.0 -d , -c config" // We always want the most granular
cmd := exec.Command("sh", "-c", pcpCommand)
// time := time.Now().Format("200601021504")
// stdout, err := os.Create("./"+time+".txt")
pipe, err := cmd.StdoutPipe()
//cmd.Stdout = stdout
scanner := bufio.NewScanner(pipe)
go func() {
// Get names of the columns
scanner.Scan()
headers := strings.Split(scanner.Text(), ",")
for _, hostMetric := range headers {
split := strings.Split(hostMetric, ":")
fmt.Printf("Host %s: Metric: %s\n", split[0], split[1])
}
// Throw away first set of results
scanner.Scan()
seconds := 0
for scanner.Scan() {
fmt.Println("Second ", seconds , " val: ", strings.Split(scanner.Text(), ","))
seconds++
}
}()
fmt.Println("PCP started: ")
if err != nil {
log.Fatal(err)
}
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
if err := cmd.Wait(); err != nil {
log.Fatal(err)
}
}