diff --git a/_assets/scripts/README.md b/_assets/scripts/README.md index d0df81dc0..5fa26d3cc 100644 --- a/_assets/scripts/README.md +++ b/_assets/scripts/README.md @@ -2,12 +2,12 @@ # extract_logs.go -This script analyzes geth.log files in a specific format and extracts information related to "sent-message" actions. It then prints relevant details such as timestamp, recipients, message ID, message type, and hashes to the console. +This script analyzes geth.log files in a specific format and extracts information related to "sent-message" actions or received messages. It then prints relevant details such as timestamp, recipients, message ID, message type, and hashes to the console. ## Usage ```bash -go run extract_logs.go +go run extract_logs.go -messages -received-message-count ``` It will output in tab separated values (TSV) diff --git a/_assets/scripts/extract_logs.go b/_assets/scripts/extract_logs.go index 03f2d0ffd..f8ea24f2a 100644 --- a/_assets/scripts/extract_logs.go +++ b/_assets/scripts/extract_logs.go @@ -3,6 +3,7 @@ package main import ( "bufio" "encoding/json" + "flag" "fmt" "os" "regexp" @@ -12,22 +13,36 @@ import ( var logPattern = regexp.MustCompile(`(?P[\d-]+T[\d:]+\.\d+Z).*(?Psent-message:.*)\s+(?P{.*})`) -func main() { - if len(os.Args) != 2 { - fmt.Println("Usage: go run script.go ") - os.Exit(1) +const ( + filtersNotMatched = "filters did match" + filtersMatched = "filters did not match" + storeNodeMessage = "received waku2 store message" +) + +func receivedMessageCountInfo(scanner *bufio.Scanner) { + fmt.Printf("Matching\tNot matching\tStore node\tLive\tTotal\n") + filtersNotMatchedCount := 0 + filtersMatchedCount := 0 + storeNodeReceivedMessageCount := 0 + + for scanner.Scan() { + line := scanner.Text() + + // Check if the line contains "sent-message" + if strings.Contains(line, filtersNotMatched) { + filtersNotMatchedCount++ + } else if strings.Contains(line, filtersMatched) { + filtersMatchedCount++ + } else if strings.Contains(line, storeNodeMessage) { + storeNodeReceivedMessageCount++ + } + // Print the required information } + fmt.Printf("%d\t%d\t%d\t%d\t%d\n", filtersNotMatchedCount, filtersMatchedCount, storeNodeReceivedMessageCount, filtersNotMatchedCount+filtersMatchedCount-storeNodeReceivedMessageCount, filtersNotMatchedCount+filtersMatchedCount) - filename := os.Args[1] - file, err := os.Open(filename) - if err != nil { - fmt.Printf("Error opening file: %s\n", err) - os.Exit(1) - } - defer file.Close() - - scanner := bufio.NewScanner(file) +} +func messagesInfo(scanner *bufio.Scanner) { fmt.Printf("Timestamp\tMessageType\tContentType\tMessageID\tHashes\tRecipients\n") for scanner.Scan() { line := scanner.Text() @@ -58,6 +73,39 @@ func main() { } } } +} + +func main() { + messagesFlag := flag.Bool("messages", false, "Process sent messages in the log file") + receivedMessageCountFlag := flag.Bool("received-message-count", false, "Count the number of sent messages in the log file") + + // Parse the flags + flag.Parse() + + if flag.NArg() != 1 { + fmt.Println("Usage: go run script.go -messages -received-message-count ") + os.Exit(1) + } + + filename := flag.Arg(0) + file, err := os.Open(filename) + if err != nil { + fmt.Printf("Error opening file: %s\n", err) + os.Exit(1) + } + defer file.Close() + + if !*messagesFlag && !*receivedMessageCountFlag { + *messagesFlag = true + } + + scanner := bufio.NewScanner(file) + + if *messagesFlag { + messagesInfo(scanner) + } else if *receivedMessageCountFlag { + receivedMessageCountInfo(scanner) + } if err := scanner.Err(); err != nil { fmt.Printf("Error reading file: %s\n", err)