# 負荷の計測 ## pprof pprofはGo標準のProfilingツール。 `net/http`にも対応していて、良い感じのエンドポイントを立ててくれる。 そこからデータをとってきて分析する。 こんなのが見れる ![](https://i.imgur.com/4oWUFRS.png) ![](https://i.imgur.com/5ZPIief.png) アプリケーションにおいて支配的な関数がわかるので結構重宝する ### サーバーアプリケーションの準備 標準の`http.ListenAndServe()`てきなものを使っている場合はimportするだけでおk ```go import _ "net/http/pprof" ``` ginとかechoとかの場合はそれぞれが対応するライブラリを出してくれている ### 計測方法 [公式Docs](https://golang.org/pkg/net/http/pprof/)に詳しい使い方が載っている ```bash go tool pprof -http=":8888" http://localhost:8080/debug/pprof/profile?seconds=30 ``` WebUIが8888で立つ。 他にも色々なエンドポイントがある ``` http://localhost:8080/debug/pprof/heap http://localhost:8080/debug/pprof/block http://localhost:8080/debug/pprof/goroutine http://localhost:8080/debug/pprof/threadcreate http://localhost:8080/debug/pprof/mutex ``` ## netdata 良い感じに負荷をグラフィカルに表示してくれる君 ### インストール ```bash bash <(curl -Ss https://my-netdata.io/kickstart.sh) all ``` ### 使い方 これをみて [リアルタイムなリソースモニタリングツールのnetdataを試してみた](https://dev.classmethod.jp/tool/netdata/) ポートは19999でListenされている