Skip to content
Snippets Groups Projects
Commit db7f21f2 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
curl_report.csv
\ No newline at end of file
# MIT Licnse
Copyright (c) 2024 SPARROW
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
README.md 0 → 100644
# SPARROW – Speed and Performance Analysis for Responsive Requests Over the Web
**SPARROW** is a script designed to perform web performance testing by making repeated `curl` requests to specified resources (CSS, PNG files) and measuring the **Time To First Byte (TTFB)** and **Total Time** for each request. The results are outputted to a CSV file for easy analysis. The script ensures that the responses are not cached and includes additional metadata in the output.
## Table of Contents
- [SPARROW – Speed and Performance Analysis for Responsive Requests Over the Web](#sparrow--speed-and-performance-analysis-for-responsive-requests-over-the-web)
- [Table of Contents](#table-of-contents)
- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Bash (Linux/macOS)](#bash-linuxmacos)
- [PowerShell (Windows)](#powershell-windows)
- [Usage](#usage)
- [Bash-Script (Linux/macOS)](#bash-script-linuxmacos)
- [PowerShell-Script (Windows)](#powershell-script-windows)
- [Options](#options)
- [CSV Output](#csv-output)
- [Example csv output:](#example-csv-output)
- [License](#license)
## Features
- Perform repeated `curl` requests to measure performance metrics.
- Capture both **TTFB** and **Total Time** for each request.
- Bypass server-side cache with a `Cache-Control` header.
- Configurable number of test repetitions and random sleep between requests.
- Metadata for `client`, `user`, and `network` included in the CSV report.
- Cross-platform support for Bash (Linux/macOS) and PowerShell (Windows).
## Requirements
- **Bash Version (Linux/macOS)**:
- `curl` must be installed.
- **PowerShell Version (Windows)**:
- Windows 10 or higher (comes with built-in `curl.exe`).
## Installation
### Bash (Linux/macOS)
1. Download the script:
```bash
wget https://your-repo-url/sparrow.sh -O sparrow.sh
```
2. Make it executable:
```bash
chmod +x sparrow.sh
```
### PowerShell (Windows)
1. Download the script:
```powershell
Invoke-WebRequest -Uri https://your-repo-url/sparrow.ps1 -OutFile sparrow.ps1
```
2. Set script execution policy (if needed):
```powershell
Set-ExecutionPolicy RemoteSigned
```
## Usage
### Bash-Script (Linux/macOS)
Run the script with the desired options:
```bash
./sparrow.sh -r 10 -m 2 -x 5 -u https://mywebsite.com -c client_xyz -U user_jane -n WiFi
```
### PowerShell-Script (Windows)
```powershell
.\sparrow.ps1 -r 10 -m 2 -x 5 -u https://mywebsite.com -c client_xyz -U user_jane -n Ethernet
```
## Options
| Option | Description | Example |
|--------|-------------|---------|
| `-r` | Number of repetitions (default: 1) | `-r 10` |
| `-m` | Minimum random sleep time between tests in seconds (default: 1) | `-m 2` |
| `-x` | Maximum random sleep time between tests in seconds (default: 5) | `-x 5` |
| `-u` | Base URL (CSS and PNG files will be appended) | `-u https://mywebsite.com` |
| `-c` | Client name to be added to CSV output | `-c client_xyz` |
| `-U` | User name to be added to CSV output | `-U user_jane` |
| `-n` | Network name to be added to CSV output | `-n WiFi` |
## CSV Output
The script generates a CSV file (`curl_report.csv`) with the following columns:
```csv
timestamp;url;ttfb;total;client;user;network
```
### Example csv output:
```csv
timestamp;url;ttfb;total;client;user;network
2024-10-09 15:30:45;https://mywebsite.com/style.css;0.056;0.230;client_xyz;user_jane;WiFi
2024-10-09 15:30:48;https://mywebsite.com/image.png;0.078;0.315;client_xyz;user_jane;WiFi
2024-10-09 15:31:45;https://mywebsite.com/style.css;0.058;0.225;client_xyz;user_jane;WiFi
...
```
## License
This project is licensed under the MIT License. See [LICENSE.md](LICENSE.md) for more details.
sparrow.png

79.2 KiB

# Default values for options
$repetitions = 1
$minSleep = 1
$maxSleep = 5
$baseUrl = "https://ardzsd.de"
$client = "default_client"
$user = "default_user"
$network = "default_network"
$outputFile = "curl_report.csv"
$cssUrl = "otrs-web/skins/Agent/default/css-cache/CommonCSS_336575c40014056de7baefb417c78be8.css"
$pngUrl = "otrs-web/skins/Agent/BR/img/ARD-ServiceDesk_RGB_72dpi.png"
# Function to perform curl and capture timing data
function Perform-Curl {
param (
[string]$url,
[string]$fileType,
[int]$iteration
)
# Get the current date and time for the test
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
# Perform the curl request, measure time and bypass cache
$curlOutput = curl.exe -o NUL -s -w "`%{time_starttransfer};`%{time_total}" -H "Cache-Control: no-cache" $url
$outputParts = $curlOutput -split ';'
$ttfb = $outputParts[0]
$totalTime = $outputParts[1]
# Append results to the CSV file
Add-Content $outputFile "$timestamp;$url;$ttfb;$totalTime;$client;$user;$network"
Write-Host "$fileType - Iteration $iteration: TTFB: $ttfb, Total Time: $totalTime"
}
# Function to get a random sleep duration between MIN and MAX
function Get-RandomSleep {
$sleepTime = Get-Random -Minimum $minSleep -Maximum $maxSleep
Write-Host "Sleeping for $sleepTime seconds..."
Start-Sleep -Seconds $sleepTime
}
# Parse command-line arguments for repetitions, sleep settings, and other options
param (
[int]$r = $repetitions,
[int]$m = $minSleep,
[int]$x = $maxSleep,
[string]$u = $baseUrl,
[string]$c = $client,
[string]$U = $user,
[string]$n = $network
)
# Set the CSS and PNG URLs based on the base URL
$cssUrl = "$u/$cssUrl"
$pngUrl = "$u/$pngUrl"
# Initialize the CSV report with headers
Add-Content $outputFile "timestamp;url;ttfb;total;client;user;network"
# Loop through the number of repetitions
for ($i = 1; $i -le $r; $i++) {
Write-Host "Test iteration $i of $r"
# Perform the curl for the CSS file
Perform-Curl $cssUrl "CSS" $i
# Perform the curl for the PNG file
Perform-Curl $pngUrl "PNG" $i
# Sleep for a random duration between the tests
if ($i -lt $r) {
Get-RandomSleep
}
}
Write-Host "Test completed. Results saved in $outputFile"
\ No newline at end of file
#!/bin/bash
# Default values for options
repetitions=1
min_sleep=1
max_sleep=5
base_url="https://ardzsd.de"
client="default_client"
user="default_user"
network="default_network"
# Output CSV file
output_file="curl_report.csv"
# Urls
css_url="otrs-web/skins/Agent/default/css-cache/CommonCSS_336575c40014056de7baefb417c78be8.css"
png_url="otrs-web/skins/Agent/BR/img/ARD-ServiceDesk_RGB_72dpi.png"
# Function to perform curl and capture timing data
perform_curl() {
url=$1
file_type=$2
iteration=$3
# Get the current date and time for the test
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
# Perform the curl request, measure time and bypass cache
curl_output=$(curl -o /dev/null -s -w "%{time_starttransfer};%{time_total}\n" \
-H 'Cache-Control: no-cache' \
"$url")
ttfb=$(echo "$curl_output" | cut -d ';' -f 1)
total_time=$(echo "$curl_output" | cut -d ';' -f 2)
# Append results to the CSV file
echo "$timestamp;$url;$ttfb;$total_time;$client;$user;$network" >> "$output_file"
echo "$file_type - Iteration $iteration: TTFB: $ttfb, Total Time: $total_time"
}
# Function to get a random sleep duration between MIN and MAX
random_sleep() {
sleep_time=$(awk -v min="$min_sleep" -v max="$max_sleep" 'BEGIN{srand(); print int(min + rand() * (max - min + 1))}')
echo "Sleeping for $sleep_time seconds..."
sleep "$sleep_time"
}
# Parse command-line arguments for number of repetitions, sleep settings, and additional options
while getopts r:m:x:u:c:U:n: flag
do
case "${flag}" in
r) repetitions=${OPTARG};;
m) min_sleep=${OPTARG};;
x) max_sleep=${OPTARG};;
u) base_url=${OPTARG};;
c) client=${OPTARG};;
U) user=${OPTARG};;
n) network=${OPTARG};;
*) echo "Invalid option";;
esac
done
# Set the CSS and PNG URLs based on the base URL
css_url="${base_url}/$css_url"
png_url="${base_url}/$png_url"
# Initialize the CSV report with headers
echo "timestamp;url;ttfb;total;client;user;network" > "$output_file"
# Loop through the number of repetitions
for ((i=1; i<=repetitions; i++))
do
echo "Test iteration $i of $repetitions"
# Perform the curl for the CSS file
perform_curl "$css_url" "CSS" $i
# Perform the curl for the PNG file
perform_curl "$png_url" "PNG" $i
# Sleep for a random duration between the tests
if [[ $i -lt $repetitions ]]; then
random_sleep
fi
done
echo "Test completed. Results saved in $output_file"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment