Added report files
This commit is contained in:
parent
83e35f17a7
commit
56c20462ff
3 changed files with 36 additions and 10 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
loadr
|
loadr
|
||||||
|
.reports
|
|
@ -1,6 +1,6 @@
|
||||||
# Loadr
|
# Loadr
|
||||||
|
|
||||||
A lightweight REST load testing tool with rubust support for different verbs, token auth, and stats.
|
A lightweight REST load testing tool with rubust support for different verbs, token auth, and performance reports.
|
||||||
|
|
||||||
Example using source:
|
Example using source:
|
||||||
|
|
||||||
|
|
41
main.go
41
main.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -169,12 +170,36 @@ func main() {
|
||||||
totalResponses += count
|
totalResponses += count
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Performance Metrics:\n")
|
// Format the results
|
||||||
fmt.Printf("Total Requests Sent: %d\n", metrics.totalRequests)
|
results := fmt.Sprintln("Performance Metrics:")
|
||||||
fmt.Printf("Total Responses Received: %d\n", totalResponses)
|
results += fmt.Sprintf("Total Requests Sent: %d\n", metrics.totalRequests)
|
||||||
fmt.Printf("Average Latency: %s\n", averageLatency)
|
results += fmt.Sprintf("Total Responses Received: %d\n", totalResponses)
|
||||||
fmt.Printf("Max Latency: %s\n", metrics.maxLatency)
|
results += fmt.Sprintf("Average Latency: %s\n", averageLatency)
|
||||||
fmt.Printf("Min Latency: %s\n", metrics.minLatency)
|
results += fmt.Sprintf("Max Latency: %s\n", metrics.maxLatency)
|
||||||
fmt.Printf("Requests Per Second (Sent): %.2f\n", float64(*requestsPerSecond))
|
results += fmt.Sprintf("Min Latency: %s\n", metrics.minLatency)
|
||||||
fmt.Printf("Responses Per Second (Received): %.2f\n", float64(totalResponses)/totalDuration)
|
results += fmt.Sprintf("Requests Per Second (Sent): %.2f\n", float64(*requestsPerSecond))
|
||||||
|
results += fmt.Sprintf("Responses Per Second (Received): %.2f\n", float64(totalResponses)/totalDuration)
|
||||||
|
|
||||||
|
// Print the results to the console
|
||||||
|
fmt.Print(results)
|
||||||
|
|
||||||
|
// Ensure the .reports directory exists
|
||||||
|
reportsDir := ".reports"
|
||||||
|
if _, err := os.Stat(reportsDir); os.IsNotExist(err) {
|
||||||
|
err := os.Mkdir(reportsDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error creating reports directory:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the results to a file in the .reports directory
|
||||||
|
timestamp := time.Now().Format("20060102-150405") // YYYYMMdd-HHmmss format
|
||||||
|
fileName := fmt.Sprintf("%s.txt", timestamp)
|
||||||
|
filePath := filepath.Join(reportsDir, fileName)
|
||||||
|
if err := os.WriteFile(filePath, []byte(results), 0644); err != nil {
|
||||||
|
fmt.Println("Error writing results to file:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue