Skip to content

Commit

Permalink
Add totalAvgResponseTime to charts
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbaldwin44 committed Dec 7, 2023
1 parent 4334e80 commit 3e89904
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 39 deletions.
1 change: 1 addition & 0 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ def stats_history(runner: "Runner") -> None:
or 0,
"response_time_percentile_2": stats.total.get_current_response_time_percentile(PERCENTILES_TO_CHART[1])
or 0,
"total_avg_response_time": stats.total.avg_response_time,
"current_response_time_percentiles": current_response_time_percentiles,
"user_count": runner.user_count or 0,
}
Expand Down
1 change: 1 addition & 0 deletions locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def request_stats() -> Response:
if stats:
report["total_rps"] = total_stats["current_rps"]
report["total_fail_per_sec"] = total_stats["current_fail_per_sec"]
report["total_avg_response_time"] = total_stats["avg_response_time"]
report["fail_ratio"] = environment.runner.stats.total.fail_ratio

if self.modern_ui:
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion locust/webui/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="theme-color" content="#000000" />

<title>Locust</title>
<script type="module" crossorigin src="/assets/index-41a98b45.js"></script>
<script type="module" crossorigin src="/assets/index-6276d787.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
13 changes: 9 additions & 4 deletions locust/webui/src/components/SwarmCharts/SwarmCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { swarmTemplateArgs } from 'constants/swarm';
import { IRootState } from 'redux/store';
import { ICharts } from 'types/ui.types';

const percentilesToChartLines = swarmTemplateArgs.percentilesToChart.map(percentile => ({
name: `${percentile * 100}th percentile`,
key: `responseTimePercentile${percentile}` as keyof ICharts,
}));

const availableSwarmCharts: ILineChartProps[] = [
{
title: 'Total Requests per Second',
Expand All @@ -16,10 +21,10 @@ const availableSwarmCharts: ILineChartProps[] = [
},
{
title: 'Response Times (ms)',
lines: swarmTemplateArgs.percentilesToChart.map(percentile => ({
name: `${percentile * 100}th percentile`,
key: `responseTimePercentile${percentile}`,
})),
lines: [
...percentilesToChartLines,
{ name: 'Average Response Time', key: 'totalAvgResponseTime' },
],
},
{
title: 'Number of Users',
Expand Down
2 changes: 2 additions & 0 deletions locust/webui/src/hooks/useSwarmUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function useSwarmUi() {
failRatio,
workers,
userCount,
totalAvgResponseTime,
} = statsData;

const time = new Date().toLocaleTimeString();
Expand All @@ -59,6 +60,7 @@ export default function useSwarmUi() {
...currentResponseTimePercentiles,
currentRps: totalRpsRounded,
currentFailPerSec: totalFailPerSecRounded,
totalAvgResponseTime: roundToDecimalPlaces(totalAvgResponseTime, 2),
userCount: userCount,
time,
};
Expand Down
3 changes: 1 addition & 2 deletions locust/webui/src/redux/slice/tests/ui.slice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const initialState = {
[responseTimePercentileKey1]: [],
currentRps: [],
currentFailPerSec: [],
responseTimePercentile1: [],
responseTimePercentile2: [],
totalAvgResponseTime: [],
userCount: [],
time: [],
},
Expand Down
3 changes: 1 addition & 2 deletions locust/webui/src/test/mocks/statsRequest.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ export const getStatsResponseTransformed = () => ({
'responseTimePercentile0.95': [2],
currentRps: [1932.5],
currentFailPerSec: [1932.5],
responseTimePercentile1: [1],
responseTimePercentile2: [1],
userCount: [1],
totalAvgResponseTime: [0.41064205516736735],
time: [new Date().toLocaleTimeString()],
},
ratios: {
Expand Down
1 change: 1 addition & 0 deletions locust/webui/src/types/swarm.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IHistory {
currentResponseTimePercentiles: {
[key: `responseTimePercentile${number}`]: number | null;
};
totalAvgResponseTime: number;
}

export interface IReport {
Expand Down
2 changes: 2 additions & 0 deletions locust/webui/src/types/ui.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface ICharts {
currentRps: (number | NullChartValue)[];
currentFailPerSec: (number | NullChartValue)[];
[key: `responseTimePercentile${number}`]: (number | null | NullChartValue)[];
totalAvgResponseTime: (number | NullChartValue)[];
userCount: (number | NullChartValue)[];
time: string[];
markers?: string[];
Expand Down Expand Up @@ -94,6 +95,7 @@ export interface IStatsResponse {
workers: ISwarmWorker[];
totalRps: number;
totalFailPerSec: number;
totalAvgResponseTime: number;
currentResponseTimePercentiles: {
[key: `responseTimePercentile${number}`]: number | null;
};
Expand Down

0 comments on commit 3e89904

Please sign in to comment.