diff options
| author | Mistivia <i@mistivia.com> | 2025-11-02 15:29:28 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-02 15:29:28 +0800 |
| commit | 9f42c2d5f911cb4e215d7873221e642ce7df4d61 (patch) | |
| tree | 6dac90a889a7402a9556d3d1bcc5cb53cdb9f123 /deprecated-webircgateway/plugins/stats | |
| parent | fb2d9de539b660a261af19b1cbcceb7ee7980cb1 (diff) | |
deprecate webircdateway and ngircd
Diffstat (limited to 'deprecated-webircgateway/plugins/stats')
| -rw-r--r-- | deprecated-webircgateway/plugins/stats/plugin.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/deprecated-webircgateway/plugins/stats/plugin.go b/deprecated-webircgateway/plugins/stats/plugin.go new file mode 100644 index 0000000..bdafc41 --- /dev/null +++ b/deprecated-webircgateway/plugins/stats/plugin.go @@ -0,0 +1,52 @@ +package main + +import ( + "fmt" + "math" + "os" + "runtime" + "sync" + "time" + + "github.com/kiwiirc/webircgateway/pkg/webircgateway" +) + +func Start(gateway *webircgateway.Gateway, pluginsQuit *sync.WaitGroup) { + gateway.Log(2, "Stats reporting plugin loading") + go reportUsage(gateway) + + pluginsQuit.Done() +} + +func reportUsage(gateway *webircgateway.Gateway) { + started := time.Now() + + out := func(line string) { + file, _ := os.OpenFile("stats_"+fmt.Sprintf("%v", started.Unix())+".csv", + os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + file.WriteString(line) + file.Close() + } + + out("time,rss,heapinuse,heapalloc,numroutines,numclients\n") + + for { + time.Sleep(time.Second * 5) + + numClients := gateway.Clients.Count() + mem := &runtime.MemStats{} + runtime.ReadMemStats(mem) + + line := fmt.Sprintf( + "%v,%v,%v,%v,%v,%v\n", + math.Round(time.Now().Sub(started).Seconds()), + mem.Sys/1024, + mem.HeapInuse/1024, + mem.HeapAlloc/1024, + runtime.NumGoroutine(), + numClients, + ) + + out(line) + } +} |
