Skip to content

Instantly share code, notes, and snippets.

@coocood
Created November 11, 2019 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coocood/6c9e3d011a23c1bfacf9c7f831848426 to your computer and use it in GitHub Desktop.
Save coocood/6c9e3d011a23c1bfacf9c7f831848426 to your computer and use it in GitHub Desktop.
jepsen analyze
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