Created
April 4, 2025 11:57
-
-
Save zoyo23/ae54b68fb0ef8cad8fe65b799de7268c to your computer and use it in GitHub Desktop.
[K6] Executa de forma estruturada organizando os arquivos de saída de acordo com a data de execução.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js"; | |
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js"; | |
import http from 'k6/http'; | |
import { sleep } from 'k6'; | |
export const options = { | |
stages: [ | |
{ duration: '5s', target: 10 }, | |
{ duration: '10s', target: 100 }, | |
{ duration: '10s', target: 500 }, | |
{ duration: '10s', target: 100 }, | |
{ duration: '5s', target: 0 }, | |
], | |
}; | |
export default () => { | |
const urlRes = http.get('https://test.k6.io'); | |
sleep(1); | |
}; | |
export function handleSummary(data) { | |
const summaryFilename = __ENV.SUMMARY_FILENAME || "summary"; | |
console.log(`Parâmetro recebido: ${summaryFilename}`); | |
// Define o nome do arquivo de saída com a data | |
const fileName = `${summaryFilename}`; | |
const fileName_html = `${fileName}_html-report.html`; | |
const fileName_json = `${fileName}.json`; | |
return { | |
[fileName_html]: htmlReport(data, { debug: false }), | |
[fileName_json]: JSON.stringify(data), | |
stdout: textSummary(data, { indent: ' ', enableColors: true }), | |
} | |
} | |
// k6.exe run index.ts | |
// k6.exe run --out 'web-dashboard' index.ts | |
// k6.exe run --out "web-dashboard=export=teste_01.htm&open=true&period=1s" index.ts | |
// k6.exe run --out "web-dashboard=export=summary_01_web-dashboard.html&open=false&period=1s" -e SUMMARY_FILENAME=summary_01 index.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM Obtém a data atual | |
set date=%DATE:~6,4%_%DATE:~3,2%_%DATE:~0,2%__%TIME:~0,2%_%TIME:~3,2%_%TIME:~6,2% | |
set date=%date: =0% | |
REM Cria um diretório com o valor da variável %date% | |
mkdir "%date%" | |
echo Diretório criado: %date% | |
REM Define o nome do arquivo de exportação com base na data | |
set export_file_name=./%date%/summary_%date% | |
echo Arquivo exportado em: %export_file_name% | |
REM Define o tempo de atualização do dashboard | |
set refresh_time_period=1s | |
echo Periodo refresh do dashboard: %refresh_time_period% | |
REM Define se o dashboard será aberto automaticamente | |
set open_dash_on_run=false | |
echo Abrir automaticamente o dashboard: %open_dash_on_run% | |
REM Armazena o comando em uma variável | |
set k6_command=k6.exe run --out "web-dashboard=export=%export_file_name%_web-dashboard.html&open=%open_dash_on_run%&period=%refresh_time_period%" -e SUMMARY_FILENAME=%export_file_name% --summary-mode=full index.ts | |
REM Exibe o comando que será executado | |
echo %k6_command% | |
REM Executa o comando armazenado na variável | |
%k6_command% |
Author
zoyo23
commented
Apr 4, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment