V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
nomoon

pprof 的端口可以换么?

  •  
  •   nomoon · Aug 13, 2016 · 2365 views
    This topic created in 3546 days ago, the information mentioned may be changed or developed.
    我开了 80 端口出去,但这个会被任何人访问。可以给 pprof 单独绑一个端口么?
    6 replies    2016-08-16 02:30:29 +08:00
    yanyuan2046
        1
    yanyuan2046  
       Aug 13, 2016
    你现在的 pprof 部分 代码怎么写的?
    zeayes
        2
    zeayes  
       Aug 13, 2016
    重新起一个 goroutine ,只监听和处理 pprof 请求。
    gamexg
        3
    gamexg  
       Aug 13, 2016
    你看了 pprof 的代码就明白了。

    ```
    Package pprof

    func init(){
    http.Handle("/debug/pprof/",http.HandlerFunc(Index))
    http.Handle("/debug/pprof/cmdline",http.HandlerFunc(Cmdline))
    http.Handle("/debug/pprof/profile",http.HandlerFunc(Profile))
    http.Handle("/debug/pprof/symbol",http.HandlerFunc(Symbol))
    http.Handle("/debug/pprof/trace",http.HandlerFunc(Trace))
    }
    ```

    http.Handle 函数:

    ```
    Func Handle(pattern string,handler Handler){DefaultServeMux.Handle(pattern,handler)}

    ```

    也就是不适用标准库默认 DefaultServeMux 就不会出现 pprof 。
    nomoon
        4
    nomoon  
    OP
       Aug 15, 2016
    @yanyuan2046 直接 import 的,并没有单独写 pprof 的东西。
    yanyuan2046
        5
    yanyuan2046  
       Aug 15, 2016
    nomoon
        6
    nomoon  
    OP
       Aug 16, 2016
    @yanyuan2046 我是现在起了一个监听 80 的 function 跑着我自己的东西。但我不想 pprof 也用 80 ,所以想问有没有办法单独为 pprof 开一个端口。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   966 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:39 · PVG 03:39 · LAX 12:39 · JFK 15:39
    ♥ Do have faith in what you're doing.