-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDosStat.java
More file actions
39 lines (32 loc) · 1.52 KB
/
Copy pathDosStat.java
File metadata and controls
39 lines (32 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.example.ddos;
import java.util.concurrent.atomic.AtomicLong;
public class DosStat {
private static final AtomicLong totalRequests = new AtomicLong();
private static final AtomicLong failedRequests = new AtomicLong();
private static final AtomicLong totalTrafficSent = new AtomicLong();
private static final AtomicLong totalTrafficReceived = new AtomicLong();
private static final AtomicLong totalSuccessTime = new AtomicLong();
private static final AtomicLong totalSuccessCount = new AtomicLong();
public static void incrementTotal() {
totalRequests.incrementAndGet();
}
public static void incrementFailed() {
failedRequests.incrementAndGet();
}
public static void recordTraffic(int sent, int received) {
totalTrafficSent.addAndGet(sent);
totalTrafficReceived.addAndGet(received);
}
public static void recordSuccess(long nanos) {
totalSuccessTime.addAndGet(nanos);
totalSuccessCount.incrementAndGet();
}
public static void printStats() {
System.out.println("Total Requests: " + totalRequests.get());
System.out.println("Failed Requests: " + failedRequests.get());
System.out.println("Traffic Sent (B): " + totalTrafficSent.get());
System.out.println("Traffic Recv (B): " + totalTrafficReceived.get());
System.out.printf("Avg Time (ms): %.2f ms%n",
totalSuccessCount.get() > 0 ? totalSuccessTime.get() / totalSuccessCount.get() / 1_000_000.0 : 0);
}
}