mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 13:42:02 +08:00
feat(webp-server): add memory usage monitoring
This commit is contained in:
parent
c9cb32b0da
commit
2b11f38480
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
"webp_server_go/config"
|
"webp_server_go/config"
|
||||||
"webp_server_go/encoder"
|
"webp_server_go/encoder"
|
||||||
"webp_server_go/handler"
|
"webp_server_go/handler"
|
||||||
@ -81,6 +82,20 @@ func init() {
|
|||||||
setupLogger()
|
setupLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func monitorMemoryUsage() {
|
||||||
|
ticker := time.NewTicker(1 * time.Minute)
|
||||||
|
for range ticker.C {
|
||||||
|
var m runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&m)
|
||||||
|
log.Infof("Alloc = %v MiB, TotalAlloc = %v MiB, Sys = %v MiB, NumGC = %v",
|
||||||
|
bToMb(m.Alloc), bToMb(m.TotalAlloc), bToMb(m.Sys), m.NumGC)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func bToMb(b uint64) uint64 {
|
||||||
|
return b / 1024 / 1024
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if config.Config.MaxCacheSize != 0 {
|
if config.Config.MaxCacheSize != 0 {
|
||||||
go schedule.CleanCache()
|
go schedule.CleanCache()
|
||||||
@ -97,6 +112,8 @@ func main() {
|
|||||||
app.Get("/healthz", handler.Healthz)
|
app.Get("/healthz", handler.Healthz)
|
||||||
app.Get("/*", handler.Convert)
|
app.Get("/*", handler.Convert)
|
||||||
|
|
||||||
|
go monitorMemoryUsage()
|
||||||
|
|
||||||
fmt.Println("WebP Server Go is Running on http://" + listenAddress)
|
fmt.Println("WebP Server Go is Running on http://" + listenAddress)
|
||||||
|
|
||||||
_ = app.Listen(listenAddress)
|
_ = app.Listen(listenAddress)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user