- Updated README.md to reflect changes in load testing commands and added usage examples for Bash scripts. - Converted PowerShell load testing scripts to Bash equivalents for better cross-platform compatibility. - Added new Bash scripts: run-loadtests.sh, summarize-artillery.sh, and summarize-k6.sh to mirror existing PowerShell functionality. - Updated admin-api.js and ws-chat.yml for consistency and improved performance metrics reporting. - Enhanced error handling and output formatting in summary scripts for better readability.
116 lines
2.9 KiB
PowerShell
116 lines
2.9 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$ReportFile
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
if (-not (Test-Path $ReportFile)) {
|
|
throw "Report file not found: $ReportFile"
|
|
}
|
|
|
|
$report = Get-Content -Raw -Path $ReportFile | ConvertFrom-Json -Depth 100
|
|
$aggregate = $report.aggregate
|
|
|
|
if (-not $aggregate) {
|
|
throw 'Artillery report is missing aggregate data.'
|
|
}
|
|
|
|
function Get-PropertyValue {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[object]$Object,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Name
|
|
)
|
|
|
|
if (-not $Object) {
|
|
return $null
|
|
}
|
|
|
|
$property = $Object.PSObject.Properties[$Name]
|
|
if ($property) {
|
|
return $property.Value
|
|
}
|
|
|
|
return $null
|
|
}
|
|
|
|
function Format-StatLine {
|
|
param(
|
|
[string]$Prefix,
|
|
[object]$Stats
|
|
)
|
|
|
|
if (-not $Stats) {
|
|
return $null
|
|
}
|
|
|
|
$parts = @()
|
|
foreach ($name in @('count', 'min', 'max', 'mean', 'median', 'p95', 'p99')) {
|
|
$value = Get-PropertyValue -Object $Stats -Name $name
|
|
if ($null -ne $value) {
|
|
$parts += "$name=$value"
|
|
}
|
|
}
|
|
|
|
if ($parts.Count -eq 0) {
|
|
return $null
|
|
}
|
|
|
|
return "$Prefix: $($parts -join ', ')"
|
|
}
|
|
|
|
$counters = Get-PropertyValue -Object $aggregate -Name 'counters'
|
|
$rates = Get-PropertyValue -Object $aggregate -Name 'rates'
|
|
$summaries = Get-PropertyValue -Object $aggregate -Name 'summaries'
|
|
|
|
$created = [double](Get-PropertyValue -Object $counters -Name 'vusers.created' ?? 0)
|
|
$failed = [double](Get-PropertyValue -Object $counters -Name 'vusers.failed' ?? 0)
|
|
$completed = [double](Get-PropertyValue -Object $counters -Name 'vusers.completed' ?? 0)
|
|
$errorRate = if ($created -gt 0) { [math]::Round(($failed / $created) * 100, 2) } else { 0 }
|
|
|
|
Write-Output '=== Artillery WebSocket Summary ==='
|
|
Write-Output "source: $ReportFile"
|
|
|
|
$timestamp = Get-PropertyValue -Object $report -Name 'timestamp'
|
|
if ($timestamp) {
|
|
Write-Output "timestamp: $timestamp"
|
|
}
|
|
|
|
if ($null -ne $created) {
|
|
Write-Output "vusers.created: $created"
|
|
}
|
|
if ($null -ne $completed) {
|
|
Write-Output "vusers.completed: $completed"
|
|
}
|
|
if ($null -ne $failed) {
|
|
Write-Output "vusers.failed: $failed"
|
|
}
|
|
Write-Output "vusers.failure_rate_percent: $errorRate"
|
|
|
|
if ($counters) {
|
|
foreach ($metric in @('ws.messages_sent', 'ws.messages_received', 'ws.ping', 'plugins.metrics-by-endpoint.response_time')) {
|
|
$value = Get-PropertyValue -Object $counters -Name $metric
|
|
if ($null -ne $value) {
|
|
Write-Output "$metric: $value"
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($rates) {
|
|
foreach ($property in $rates.PSObject.Properties) {
|
|
Write-Output "rate.$($property.Name): $($property.Value)"
|
|
}
|
|
}
|
|
|
|
if ($summaries) {
|
|
foreach ($property in $summaries.PSObject.Properties) {
|
|
$line = Format-StatLine -Prefix "summary.$($property.Name)" -Stats $property.Value
|
|
if ($line) {
|
|
Write-Output $line
|
|
}
|
|
}
|
|
}
|