Skip to content

Commit 8aa3262

Browse files
authored
Fixed /s analytics display and changed screenshot
There were 2 resets so sometimes it showed 0 Also you can configure interval to reset now changed ss cuz ppl said traffic was weak
1 parent 51c0694 commit 8aa3262

11 files changed

Lines changed: 486 additions & 470 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ blocklist:
112112
enabled: true # Enable blocklist
113113
blocktime: 60 # How many seconds to wait before cleaning the blocklist
114114
global: true # Drop all traffic from blocked IPs regardless of Protocol or Destination
115+
116+
stats:
117+
interval: 5 # Seconds – window over which PPS/BPS stats are aggregated
115118
```
116119
117120
---
@@ -154,4 +157,4 @@ For a budget-friendly alternative for your small server, visit **[Arvoris](https
154157

155158
## License
156159

157-
See `LICENSE` file for details.
160+
See `LICENSE` file for details.

analytics/drop_bps.go

Lines changed: 65 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,65 @@
1-
package analytics
2-
3-
import (
4-
"log"
5-
"time"
6-
7-
xdp "bedrock-xdp/xdp_utils"
8-
9-
"github.com/cilium/ebpf"
10-
)
11-
12-
var (
13-
udpDropBPS *ebpf.Map // udp_drop_bps
14-
otherDropBPS *ebpf.Map // other_drop_bps
15-
)
16-
17-
//Counter reset logic and Map Lookups should probably be reworked but what do you expect, this is open source.
18-
19-
func StartDroppedBPS(Collection *ebpf.Collection) {
20-
udpDropBPS = xdp.GetMap("udp_drop_bps", Collection)
21-
otherDropBPS = xdp.GetMap("other_drop_bps", Collection)
22-
23-
ticker := time.NewTicker(1 * time.Second)
24-
for range ticker.C {
25-
resetDropBitCount()
26-
}
27-
}
28-
29-
func resetDropBitCount() {
30-
var resetCount uint64 = 0
31-
var totalKey uint32 = 0
32-
33-
if udpDropBPS != nil {
34-
udpDropBPS.Update(&totalKey, &resetCount, ebpf.UpdateAny)
35-
}
36-
if otherDropBPS != nil {
37-
otherDropBPS.Update(&totalKey, &resetCount, ebpf.UpdateAny)
38-
}
39-
40-
resetByteCountMap(udpDropBPS)
41-
resetByteCountMap(otherDropBPS)
42-
}
43-
44-
func resetByteCountMap(byteCountMap *ebpf.Map) {
45-
if byteCountMap == nil {
46-
return
47-
}
48-
var key uint32
49-
var resetCount uint64 = 0
50-
51-
iter := byteCountMap.Iterate()
52-
for iter.Next(&key, &resetCount) {
53-
byteCountMap.Update(&key, &resetCount, ebpf.UpdateAny)
54-
}
55-
56-
if err := iter.Err(); err != nil {
57-
log.Printf("Error resetting byte count map: %s\n", err)
58-
}
59-
}
60-
61-
func GetTotalDroppedBPS(check string) uint64 {
62-
switch check {
63-
case "udp":
64-
return getMapTotalCount(udpDropBPS)
65-
case "other":
66-
return getMapTotalCount(otherDropBPS)
67-
default:
68-
return getMapTotalCount(udpDropBPS) + getMapTotalCount(otherDropBPS)
69-
}
70-
}
1+
package analytics
2+
3+
import (
4+
"log"
5+
6+
xdp "bedrock-xdp/xdp_utils"
7+
8+
"github.com/cilium/ebpf"
9+
)
10+
11+
var (
12+
udpDropBPS *ebpf.Map // udp_drop_bps
13+
otherDropBPS *ebpf.Map // other_drop_bps
14+
)
15+
16+
//Counter reset logic and Map Lookups should probably be reworked but what do you expect, this is open source.
17+
18+
func StartDroppedBPS(Collection *ebpf.Collection) {
19+
udpDropBPS = xdp.GetMap("udp_drop_bps", Collection)
20+
otherDropBPS = xdp.GetMap("other_drop_bps", Collection)
21+
}
22+
23+
// ResetDropBPS clears dropped bit counters.
24+
func ResetDropBPS() {
25+
var resetCount uint64 = 0
26+
var totalKey uint32 = 0
27+
28+
if udpDropBPS != nil {
29+
udpDropBPS.Update(&totalKey, &resetCount, ebpf.UpdateAny)
30+
}
31+
if otherDropBPS != nil {
32+
otherDropBPS.Update(&totalKey, &resetCount, ebpf.UpdateAny)
33+
}
34+
35+
resetByteCountMap(udpDropBPS)
36+
resetByteCountMap(otherDropBPS)
37+
}
38+
39+
func resetByteCountMap(byteCountMap *ebpf.Map) {
40+
if byteCountMap == nil {
41+
return
42+
}
43+
var key uint32
44+
var resetCount uint64 = 0
45+
46+
iter := byteCountMap.Iterate()
47+
for iter.Next(&key, &resetCount) {
48+
byteCountMap.Update(&key, &resetCount, ebpf.UpdateAny)
49+
}
50+
51+
if err := iter.Err(); err != nil {
52+
log.Printf("Error resetting byte count map: %s\n", err)
53+
}
54+
}
55+
56+
func GetTotalDroppedBPS(check string) uint64 {
57+
switch check {
58+
case "udp":
59+
return getMapTotalCount(udpDropBPS) / uint64(StatIntervalSec)
60+
case "other":
61+
return getMapTotalCount(otherDropBPS) / uint64(StatIntervalSec)
62+
default:
63+
return (getMapTotalCount(udpDropBPS) + getMapTotalCount(otherDropBPS)) / uint64(StatIntervalSec)
64+
}
65+
}

analytics/drop_pps.go

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,46 @@
1-
package analytics
2-
3-
import (
4-
"time"
5-
6-
xdp "bedrock-xdp/xdp_utils"
7-
8-
"github.com/cilium/ebpf"
9-
)
10-
11-
var (
12-
udpDropPPS *ebpf.Map // udp_drop_pps
13-
otherDropPPS *ebpf.Map // other_drop_pps
14-
)
15-
16-
//Counter reset logic and Map Lookups should probably be reworked but what do you expect, this is open source.
17-
18-
func StartDroppedPPS(Collection *ebpf.Collection) {
19-
udpDropPPS = xdp.GetMap("udp_drop_pps", Collection)
20-
otherDropPPS = xdp.GetMap("other_drop_pps", Collection)
21-
22-
ticker := time.NewTicker(1 * time.Second)
23-
for range ticker.C {
24-
resetDropCount()
25-
}
26-
}
27-
28-
func resetDropCount() {
29-
var resetCount uint64 = 0
30-
var totalKey uint32 = 0
31-
32-
if udpDropPPS != nil {
33-
udpDropPPS.Update(&totalKey, &resetCount, ebpf.UpdateAny)
34-
}
35-
if otherDropPPS != nil {
36-
otherDropPPS.Update(&totalKey, &resetCount, ebpf.UpdateAny)
37-
}
38-
39-
resetPacketCountMap(udpDropPPS)
40-
resetPacketCountMap(otherDropPPS)
41-
}
42-
43-
func GetTotalDroppedPPS(check string) uint64 {
44-
switch check {
45-
case "udp":
46-
return getMapTotalCount(udpDropPPS)
47-
case "other":
48-
return getMapTotalCount(otherDropPPS)
49-
default:
50-
return getMapTotalCount(udpDropPPS) + getMapTotalCount(otherDropPPS)
51-
}
52-
}
1+
package analytics
2+
3+
import (
4+
xdp "bedrock-xdp/xdp_utils"
5+
6+
"github.com/cilium/ebpf"
7+
)
8+
9+
var (
10+
udpDropPPS *ebpf.Map // udp_drop_pps
11+
otherDropPPS *ebpf.Map // other_drop_pps
12+
)
13+
14+
//Counter reset logic and Map Lookups should probably be reworked but what do you expect, this is open source.
15+
16+
func StartDroppedPPS(Collection *ebpf.Collection) {
17+
udpDropPPS = xdp.GetMap("udp_drop_pps", Collection)
18+
otherDropPPS = xdp.GetMap("other_drop_pps", Collection)
19+
}
20+
21+
// ResetDropPPS clears dropped packet counters.
22+
func ResetDropPPS() {
23+
var resetCount uint64 = 0
24+
var totalKey uint32 = 0
25+
26+
if udpDropPPS != nil {
27+
udpDropPPS.Update(&totalKey, &resetCount, ebpf.UpdateAny)
28+
}
29+
if otherDropPPS != nil {
30+
otherDropPPS.Update(&totalKey, &resetCount, ebpf.UpdateAny)
31+
}
32+
33+
resetPacketCountMap(udpDropPPS)
34+
resetPacketCountMap(otherDropPPS)
35+
}
36+
37+
func GetTotalDroppedPPS(check string) uint64 {
38+
switch check {
39+
case "udp":
40+
return getMapTotalCount(udpDropPPS) / uint64(StatIntervalSec)
41+
case "other":
42+
return getMapTotalCount(otherDropPPS) / uint64(StatIntervalSec)
43+
default:
44+
return (getMapTotalCount(udpDropPPS) + getMapTotalCount(otherDropPPS)) / uint64(StatIntervalSec)
45+
}
46+
}

0 commit comments

Comments
 (0)