cmd/stats-read/main.go | 27 +++++++++++++++++++-------- diff --git a/cmd/stats-read/main.go b/cmd/stats-read/main.go index d424b0de94c3218a2d9df26e6cd89cc23f9c603f5760229d63f8be7d7ded649d..52674a1c93a30fd5def6cdb29e2ecced39aa8f997cb06af7dc214ef6748be49e 100644 --- a/cmd/stats-read/main.go +++ b/cmd/stats-read/main.go @@ -11,6 +11,8 @@ "io" "log" "os" "path" + "slices" + "strconv" "time" "github.com/dchest/siphash" @@ -37,7 +39,16 @@ func main() { db := flag.String("db", "stats", "Path to stats database") fromStr := flag.String("from", "1970-01-01 00:00:00", "Since date") tillStr := flag.String("till", "3000-01-01 00:00:00", "Till date") - code := flag.Uint("code", 0, "Show only that status code") + var codes []int + flag.Func("code", "Show only that status code", + func(s string) error { + i, err := strconv.Atoi(s) + if err != nil { + return err + } + codes = append(codes, i) + return nil + }) showURLs := flag.Bool("urls", false, "Show URLs") showSize := flag.Bool("size", false, "Show size instead of counter") flag.Parse() @@ -45,7 +56,7 @@ from := parseTime(*fromStr) till := parseTime(*tillStr) var skip bool - var statusCode uint16 + var statusCode int buf := make([]byte, 8*3) zeros := make([]byte, 8-2) var tai tai64n.TAI64 @@ -61,7 +72,7 @@ if err != nil { break } if !bytes.Equal(buf[8+8+2:], zeros) { - log.Println("bad zero terminator", buf[8+8+2:]) + log.Println("bad zero terminator", hex.EncodeToString(buf[8+8+2:])) break } skip = false @@ -69,8 +80,8 @@ if bytes.Compare(buf[:8], from[:]) == -1 || bytes.Compare(buf[:8], till[:]) >= 0 { skip = true } - statusCode = binary.BigEndian.Uint16(buf[8+8 : 8+8+2]) - if *code != 0 && statusCode != uint16(*code) { + statusCode = int(binary.BigEndian.Uint16(buf[8+8 : 8+8+2])) + if len(codes) > 0 && !slices.Contains(codes, statusCode) { skip = true } if !skip { @@ -143,7 +154,7 @@ if err != nil { break } if !bytes.Equal(buf[8+8+2:], zeros) { - log.Println("bad zero terminator", buf[8+8+2:]) + log.Println("bad zero terminator", hex.EncodeToString(buf[8+8+2:])) break } skip = false @@ -151,8 +162,8 @@ if bytes.Compare(buf[:8], from[:]) == -1 || bytes.Compare(buf[:8], till[:]) >= 0 { skip = true } - statusCode = binary.BigEndian.Uint16(buf[8+8 : 8+8+2]) - if *code != 0 && statusCode != uint16(*code) { + statusCode = int(binary.BigEndian.Uint16(buf[8+8 : 8+8+2])) + if len(codes) > 0 && !slices.Contains(codes, statusCode) { skip = true } if !skip {