56 lines
1.8 KiB
PowerShell
56 lines
1.8 KiB
PowerShell
# Mide latencia HTTP de count-api vía gateway para cada PDF en docs/plan_pruebas/data/
|
|
param(
|
|
[string]$BaseUrl = "http://127.0.0.1:8189",
|
|
[string]$DataDir = "",
|
|
[string]$OutCsv = ""
|
|
)
|
|
|
|
$Root = Resolve-Path (Join-Path $PSScriptRoot "..\..\..")
|
|
if (-not $DataDir) { $DataDir = Join-Path $Root "docs\plan_pruebas\data" }
|
|
if (-not $OutCsv) {
|
|
$stamp = Get-Date -Format "yyyyMMdd"
|
|
$OutCsv = Join-Path $Root "docs\plan_pruebas\informes\count_latency_$stamp.csv"
|
|
}
|
|
|
|
if (-not (Test-Path $DataDir)) { throw "No existe DataDir=$DataDir" }
|
|
$pdfs = Get-ChildItem -Path $DataDir -Filter *.pdf -File
|
|
if ($pdfs.Count -eq 0) { throw "No hay PDFs en $DataDir" }
|
|
|
|
New-Item -ItemType Directory -Force -Path (Split-Path $OutCsv) | Out-Null
|
|
"file,http_time_s,http_code,service_count,status" | Set-Content -Path $OutCsv -Encoding utf8
|
|
Write-Host "BASE_URL=$BaseUrl"
|
|
Write-Host "DATA_DIR=$DataDir"
|
|
Write-Host "OUT=$OutCsv"
|
|
|
|
foreach ($pdf in $pdfs) {
|
|
$tmp = [System.IO.Path]::GetTempFileName()
|
|
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
|
try {
|
|
$resp = curl.exe -sS -o $tmp -w "%{http_code}" `
|
|
-F "files=@$($pdf.FullName);type=application/pdf" `
|
|
"$BaseUrl/count/v1/count"
|
|
$code = $resp.Trim()
|
|
} catch {
|
|
$code = "000"
|
|
}
|
|
$sw.Stop()
|
|
$secs = [math]::Round($sw.Elapsed.TotalSeconds, 3)
|
|
$scount = ""
|
|
$status = "parse_error"
|
|
try {
|
|
$json = Get-Content $tmp -Raw | ConvertFrom-Json
|
|
if ($json.results -and $json.results.Count -gt 0) {
|
|
$scount = $json.results[0].service_count
|
|
$status = $json.results[0].status
|
|
} elseif ($json.error) {
|
|
$status = $json.error
|
|
}
|
|
} catch {}
|
|
$line = "$($pdf.Name),$secs,$code,$scount,$status"
|
|
Add-Content -Path $OutCsv -Value $line
|
|
Write-Host $line
|
|
Remove-Item $tmp -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
Write-Host "Done. CSV: $OutCsv"
|