pyroscope 模組提供與 Pyroscope 的集成,用於生產監控和性能分析。
加載 Pyroscope 服務器地址並開始分析。
func load(address string)
參數:
address
行為:
示例:
pyroscope.load("http://localhost:4040")
func main() { // 開始分析 pyroscope.load("http://localhost:4040") // 應用程序代碼 runApplication() }
func setupMonitoring() { address := os.Getenv("PYROSCOPE_ADDRESS") if address == "" { address = "http://localhost:4040" } pyroscope.load(address) log.Info("Pyroscope profiling enabled") }
// 好的做法: 配置 Pyroscope 地址 address := os.Getenv("PYROSCOPE_ADDRESS") if address == "" { address = "http://localhost:4040" } // 好的做法: 處理連接錯誤 pyroscope.load(address) // 連接錯誤會被記錄