Repository: locustio/locust

Issue:
Total RPS Charts | Failures line chart does not display current number of failures
### Prerequisites

- [X] I am using [the latest version of Locust](https://github.com/locustio/locust/releases/)
- [X] I am reporting a bug, not asking a question

### Description

The failures line chart does not show the current number of failures over time. 

I have to refresh the page to get the line chart updated on the chart, The green RPS line does update and show up however the red line goes to 0 and it stays there.

1. Opens the charts tab
2. The next time the chart refreshes the failures line goes to zero and stays there

![Screenshot 2023-11-16 at 17 23 00](https://github.com/locustio/locust/assets/6494108/04ae05cc-6da6-426e-84ce-b6969e7d0c05)

3. Refresh the page to see the failures.
4. Red line goes to zero and stays there over time.
![Screenshot 2023-11-16 at 17 23 11](https://github.com/locustio/locust/assets/6494108/14cab723-ee4e-4e0c-8095-8ac6dd7449c2)



### Command line

-f my_test.py --autostart --modern-ui

### Locustfile contents

```python3
N/A
```


### Python version

3.11

### Locust version

2.18.3

### Operating system

MacOS


Discussion:
Ping @andrewbaldwin44 
Hi @borget, I had the tests running for over ten minutes and I was not able to reproduce your issue. Could you please add some more information?
- Are you able to reproduce this issue using the old UI?
- If possible, could you include the contents of your locust file?

> Hi @borget, I had the tests running for over ten minutes and I was not able to reproduce your issue. Could you please add some more information?
> 


Hi @andrewbaldwin44,

Absolutely, 

> * Are you able to reproduce this issue using the old UI?

No I am not, the issue is not present in the old UI when running the same test.


> * If possible, could you include the contents of your locust file?

Below relevant details about the locust file,

```python

class FastUser(FastHttpUser):
    tasks = [FastUserTasks]


class FastUserTasks(TaskSet):
    @tag("Task1")
    @task(1)
    def task1(self):
        """
        I omitted how below variables are generated. Overall, there is some logic that generates protobuf messages
        that are sent as binary over http post action when executing the tasks, I have around 22 tasks that send 
        different protobuf messages.
        """
        self.client.post(
            url,
            name=f"/{message_type}",
            data=message,
            headers={
                "Content-Type": "application/octet-stream"
            }
        )

```

Please let me know if you need any extra information.


Resolving patch:
diff --git a/locust/web.py b/locust/web.py
--- a/locust/web.py
+++ b/locust/web.py
@@ -367,6 +367,7 @@ def request_stats() -> Response:
                     "stats": stats,
                     "errors": errors,
                     "total_rps": 0.0,
+                    "total_fail_per_sec": 0.0,
                     "fail_ratio": 0.0,
                     "current_response_time_percentile_1": None,
                     "current_response_time_percentile_2": None,
@@ -395,9 +396,11 @@ def request_stats() -> Response:
                 truncated_stats += [stats[-1]]
 
             report = {"stats": truncated_stats, "errors": errors[:500]}
+            total_stats = stats[-1]
 
             if stats:
-                report["total_rps"] = stats[len(stats) - 1]["current_rps"]
+                report["total_rps"] = total_stats["current_rps"]
+                report["total_fail_per_sec"] = total_stats["current_fail_per_sec"]
                 report["fail_ratio"] = environment.runner.stats.total.fail_ratio
                 report[
                     "current_response_time_percentile_1"


Test patch: