Last active
January 31, 2019 16:21
-
-
Save jim-minter/39bab11174e169729cde2f8d1cccecfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"os" | |
"regexp" | |
"strconv" | |
"strings" | |
"time" | |
) | |
func stress(i int) { | |
f, _ := os.Create(fmt.Sprintf("file%d", i)) | |
i = 0 | |
for { | |
f.Seek(0, 0) | |
fmt.Fprintf(f, "%d", i) | |
f.Sync() | |
i++ | |
} | |
} | |
var r = regexp.MustCompile(`\s+`) | |
func main() { | |
j, _ := strconv.Atoi(os.Args[1]) | |
for i := 0; i < j; i++ { | |
go stress(i) | |
} | |
t := time.Tick(time.Second) | |
start := time.Now() | |
startios := 0 | |
for { | |
b, _ := ioutil.ReadFile(fmt.Sprintf("/sys/block/%s/stat", os.Args[2])) | |
fields := r.Split(strings.TrimSpace(string(b)), -1) | |
ios, _ := strconv.Atoi(fields[4]) | |
if startios == 0 { | |
startios = ios | |
} else { | |
fmt.Println((ios - startios) / int(time.Now().Sub(start)/time.Second)) | |
} | |
<-t | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment