mirror of
https://github.com/fosrl/gerbil.git
synced 2026-10-20 19:49:07 +02:00
@@ -15,6 +15,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -150,8 +151,6 @@ func parseLogLevel(level string) logger.LogLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go monitorMemory(1024 * 1024 * 512) // trigger if memory usage exceeds 512MB
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
wgconfig WgConfig
|
wgconfig WgConfig
|
||||||
@@ -344,6 +343,15 @@ func main() {
|
|||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// Heap profiles are dumped into the configured config directory (the same
|
||||||
|
// directory as the config file, or /var/config as a fallback for remote-config
|
||||||
|
// setups) so they land on the volume the operator actually has mounted.
|
||||||
|
heapDir := "/var/config/heap"
|
||||||
|
if configFile != "" {
|
||||||
|
heapDir = filepath.Join(filepath.Dir(configFile), "heap")
|
||||||
|
}
|
||||||
|
go monitorMemory(1024*1024*512, heapDir) // trigger if memory usage exceeds 512MB
|
||||||
|
|
||||||
// Derive IFB device name from the WireGuard interface name (Linux limit: 15 chars)
|
// Derive IFB device name from the WireGuard interface name (Linux limit: 15 chars)
|
||||||
ifbName = "ifb_" + interfaceName
|
ifbName = "ifb_" + interfaceName
|
||||||
if len(ifbName) > 15 {
|
if len(ifbName) > 15 {
|
||||||
@@ -1599,7 +1607,7 @@ func notifyPeerChange(action, publicKey string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func monitorMemory(limit uint64) {
|
func monitorMemory(limit uint64, heapDir string) {
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
for {
|
for {
|
||||||
runtime.ReadMemStats(&m)
|
runtime.ReadMemStats(&m)
|
||||||
@@ -1615,8 +1623,9 @@ func monitorMemory(limit uint64) {
|
|||||||
// Record memory spike metric
|
// Record memory spike metric
|
||||||
metrics.RecordMemorySpike(severity)
|
metrics.RecordMemorySpike(severity)
|
||||||
|
|
||||||
f, err := os.Create(fmt.Sprintf("/var/config/heap/heap-spike-%d.pprof", time.Now().Unix()))
|
if err := os.MkdirAll(heapDir, 0o755); err != nil {
|
||||||
if err != nil {
|
log.Println("could not create heap profile directory:", err)
|
||||||
|
} else if f, err := os.Create(filepath.Join(heapDir, fmt.Sprintf("heap-spike-%d.pprof", time.Now().Unix()))); err != nil {
|
||||||
log.Println("could not create profile:", err)
|
log.Println("could not create profile:", err)
|
||||||
} else {
|
} else {
|
||||||
pprof.WriteHeapProfile(f)
|
pprof.WriteHeapProfile(f)
|
||||||
|
|||||||
Reference in New Issue
Block a user