This repository has been archived on 2024-04-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elektron/pcp/pcp.go

57 lines
1 KiB
Go
Raw Normal View History

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)
}
}