I have some chips running on some hardware and I want to bind the output of a shell command to a struct to do reporting/logging on.
Num item1: 2
INDEX LOAD MODEL_LOAD INST MEM SHARE_MEM P2P_MEM DEVICE NAMESPACE
1 2 3 4 50 600 700 1 1
1a 2b 3c 4c 5d 6e 7f 2 2
Num item2: 2
INDEX LOAD MODEL_LOAD INST MEM SHARE_MEM P2P_MEM DEVICE NAMESPACE
2a 2b 2c 3 0 0 0 1 1
1 0 0 0 0 0 0 2 2
**************************************************
Attempt
cat out.txt | grep -i "Num $1" -A 3 | grep -i nvme | tr -s ' ' | cut -d' ' -f1-7
This actually isn't too bad, I can pass in an arg like decoders or encoders and get the load metrics for each chip. However, I'm curious now the best way to bind this to a struct in Go.
Currently, what I can do is code up a custom deserializer from something like:
func main() {
out, err := exec.Command("/bin/sh", "metrics.sh", "encoders").Output()
if err != nil {
fmt.Println(err)
log.Fatal(err)
}
fmt.Println(string(out))
}
But I feel like there has to be a better way, like outputting as JSON and binding to a struct or something.