PCP code is now able to deal with receiving information asynchronously from pmdumptext
This commit is contained in:
parent
e0dc0c7368
commit
fa3a620fba
3 changed files with 57 additions and 27 deletions
1
metrics.go
Normal file
1
metrics.go
Normal file
|
@ -0,0 +1 @@
|
|||
package electron
|
27
pcp.go
27
pcp.go
|
@ -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
56
pcp/pcp.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in a new issue