Created
November 11, 2019 09:17
-
-
Save coocood/6c9e3d011a23c1bfacf9c7f831848426 to your computer and use it in GitHub Desktop.
jepsen analyze
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 ( | |
"bufio" | |
"bytes" | |
"flag" | |
"github.com/prometheus/common/log" | |
"io" | |
"os" | |
"strconv" | |
) | |
var fileName = flag.String("file", "jepsen.log", "jepsen log file") | |
func main() { | |
flag.Parse() | |
fileNameStr := *fileName | |
file, _ := os.Open(fileNameStr) | |
reader := bufio.NewReader(file) | |
cnt := 0 | |
for { | |
line, _, err := reader.ReadLine() | |
if err != nil { | |
if err != io.EOF { | |
panic(err) | |
} | |
break | |
} | |
cnt++ | |
sep := []byte(":ok\t:read") | |
if idx := bytes.Index(line, sep); idx != -1 { | |
line = line[idx:] | |
begin := bytes.IndexByte(line, '{') | |
end := bytes.IndexByte(line, '}') | |
pairs := bytes.Split(line[begin+1:end], []byte(", ")) | |
var sum int | |
for _, pair := range pairs { | |
spaceIdx := bytes.IndexByte(pair, ' ') | |
num, err := strconv.Atoi(string(pair[spaceIdx+1:])) | |
if err != nil { | |
panic(err.Error() + string(line)) | |
} | |
sum += num | |
} | |
if sum != 100 { | |
log.Errorf("sum is %d, line:%d", sum, cnt) | |
break | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment