Closed txxxxc closed 1 month ago
そもそもpprofがなにか分かってない performance profilingの略っぽい。
Flame Graphの読み方もめっちゃざっくり分かった
横幅: 関数の実行時間の長さを表す 縦方向: 関数の呼び出し階層を表す 色: 特定の意味はない
ざっくりいうとpprof周りの設定をやってくれてるらしい
echov4.EnableDebugHandler(e)
[Go] pprofでのプロファイル(計測)のやり方を改めて整理した #Go - Qiita
HTTPサーバなど定常的に動いているプログラムに対して一定時間の間プロファイルしたい場合はnet/http/pprofを利用します。 importに_ net/http/pprofを追加し、対象の定常的なプログラムに
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
これ意味わからん過ぎる
initでエンドポイントを追加してるっぽいです
func init() {
http.HandleFunc("/debug/pprof/", Index)
http.HandleFunc("/debug/pprof/cmdline", Cmdline)
http.HandleFunc("/debug/pprof/profile", Profile)
http.HandleFunc("/debug/pprof/symbol", Symbol)
http.HandleFunc("/debug/pprof/trace", Trace)
}
mysqlとnginxのログの設定を終わってるから一旦これで終わりっぽい?
一旦pproteinのweb uiを起動してみても良いかもしれん
Cloud Formationとかsystemdの例はあるけど、dockerはないから頑張る まあいうても本家のリポジトリにあるけど https://github.com/kaz/pprotein/blob/master/compose.yaml
一旦本家のDockerfileパクったけど、マルチステージビルドがわからんすぎる
なかなかわかりやすかった マルチステージビルドの利用 | Docker ドキュメント
WORKDIRで存在しないディレクトリを指定したら、ディレクトリを作ってくれるらしい
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn't exist, it will be created even if it's not used in any subsequent Dockerfile instruction.
一旦サーバーは起動できた ログファイルをhttpから取得できるようにしないといけない(めんどいかもしれん)
pprotein-agentがそれをやってくれるかもしれんから調べてみましょう
tailHandlerってやつでファイルを読んでresponseとして返すっていう動きをしてるっぽいです https://github.com/kaz/pprotein/blob/bc90ef9cd3e0df4deba81f367c177c5539b87def/internal/tail/tail.go#L61-L85
var (
httplogPath = getEnvOrDefault("PPROTEIN_HTTPLOG", "/var/log/nginx/access.log")
slowlogPath = getEnvOrDefault("PPROTEIN_SLOWLOG", "/var/log/mysql/mysql-slow.log")
gitRepositoryPath = getEnvOrDefault("PPROTEIN_GIT_REPOSITORY", ".")
)
ほなpproteinのagentも起動する必要がある?
pprotein-agent意味わからんすぎたけどなんとなく理解できた
pprotein本家の方はまだあんまり理解してないから一旦読んでみるか
まあでも一旦動くか試してみても良い
nginxのログはlstvに変えないと行けないっぽい
便利すぎる
e.GET("/*", echo.WrapHandler(http.FileServer(http.FS(fs))))
http.FileServerは、Goの標準ライブラリに含まれるHTTPハンドラで、指定されたディレクトリ内のファイルを提供するためのものです。このハンドラは、リクエストされたファイルをディレクトリから探し、見つかった場合はそのファイルを返します。例えば、静的なウェブサイトのファイルやリソースを提供するのに便利です。 具体的には、以下のように動作します: http.FileServer(http.FS(fs))は、fsで指定されたファイルシステムからファイルを取得し、HTTPリクエストに応じてそのファイルを返します。 e.GET("/*", ...)は、すべてのリクエストに対してこのファイルサーバーを適用し、リクエストされたパスに基づいて適切なファイルを提供します。 このようにして、アプリケーションは静的ファイルを簡単に配信できます。
普通にgo:embedを調べた
go:embedは、Go言語の機能で、ファイルやディレクトリをバイナリに埋め込むために使用されます。このディレクティブを使うことで、外部ファイルをプログラムの実行時に直接利用できるようになります。例えば、HTML、CSS、画像ファイルなどを埋め込むことができます。 上記の例では、distディレクトリ内のすべてのファイルがdistという変数に埋め込まれています。これにより、埋め込まれたファイルにアクセスするためのembed.FS型のファイルシステムが作成されます。
package main
import (
"embed"
"fmt"
"net/http"
)
//go:embed index.html
var content embed.FS
func handler(w http.ResponseWriter, r *http.Request) {
data, err := content.ReadFile("index.html")
if err != nil {
http.Error(w, "File not found", http.StatusNotFound)
return
}
w.Write(data)
}
func main() {
http.HandleFunc("/", handler)
fmt.Println("Server is running on :8080")
http.ListenAndServe(":8080", nil)
}
pproteinがログファイルとかをどうやって取得しているかについてはなんとなくわかりました。
あとはこいつが何をやってるか調べる
echov4.EnableDebugHandler(e)
こいつが何をやっているかは分かった とりあえずこれらのところにファイルがあれば耐えそう
httplogPath = getEnvOrDefault("PPROTEIN_HTTPLOG", "/var/log/nginx/access.log")
slowlogPath = getEnvOrDefault("PPROTEIN_SLOWLOG", "/var/log/mysql/mysql-slow.log")
gitRepositoryPath = getEnvOrDefault("PPROTEIN_GIT_REPOSITORY", ".")
一旦導入DONEかなり便利かもしれない
まじでわからんけど頑張ります