LoginSignup
3
0

More than 5 years have passed since last update.

Echo で net/http/pprof をマウントする

Posted at

echo は DefaultServeMux を使っていないので手動でマウントする必要がある。

echo には echo.WrapHandler や echo.WrapMiddleware という便利なヘルパ関数が用意されてるのでそれを使えばいい。

package main

import (
    "net/http"
    "net/http/pprof"

    "github.com/labstack/echo"
)

func main() {
    e := echo.New()

    pprofGroup := e.Group("/debug/pprof")
    pprofGroup.Any("/cmdline", echo.WrapHandler(http.HandlerFunc(pprof.Cmdline)))
    pprofGroup.Any("/profile", echo.WrapHandler(http.HandlerFunc(pprof.Profile)))
    pprofGroup.Any("/symbol", echo.WrapHandler(http.HandlerFunc(pprof.Symbol)))
    pprofGroup.Any("/trace", echo.WrapHandler(http.HandlerFunc(pprof.Trace)))
    pprofGroup.Any("/*", echo.WrapHandler(http.HandlerFunc(pprof.Index)))

    e.Start(":8080")
}

goroutine や heap などの Profile の取得は Index ハンドラに含まれているのでワイルドカードで流し込んでしまう。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0