Skip to content

Commit

Permalink
support pprof (fatedier#2849)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier authored Mar 17, 2022
1 parent 37c2716 commit 63efa6b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
14 changes: 12 additions & 2 deletions client/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package client
import (
"net"
"net/http"
"net/http/pprof"
"time"

"github.com/fatedier/frp/assets"
Expand All @@ -26,8 +27,8 @@ import (
)

var (
httpServerReadTimeout = 10 * time.Second
httpServerWriteTimeout = 10 * time.Second
httpServerReadTimeout = 60 * time.Second
httpServerWriteTimeout = 60 * time.Second
)

func (svr *Service) RunAdminServer(address string) (err error) {
Expand All @@ -36,6 +37,15 @@ func (svr *Service) RunAdminServer(address string) (err error) {

router.HandleFunc("/healthz", svr.healthz)

// debug
if svr.cfg.PprofEnable {
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
router.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index)
}

subRouter := router.NewRoute().Subrouter()
user, passwd := svr.cfg.AdminUser, svr.cfg.AdminPwd
subRouter.Use(frpNet.NewHTTPAuthMiddleware(user, passwd).Middleware)
Expand Down
4 changes: 4 additions & 0 deletions conf/frpc_full.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ udp_packet_size = 1500
# If DisableCustomTLSFirstByte is true, frpc will not send that custom byte.
disable_custom_tls_first_byte = false

# Enable golang pprof handlers in admin listener.
# Admin port must be set first.
pprof_enable = false

# 'ssh' is the unique proxy name
# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh'
[ssh]
Expand Down
4 changes: 4 additions & 0 deletions conf/frps_full.ini
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ tcp_mux = true
# It affects the udp and sudp proxy.
udp_packet_size = 1500

# Enable golang pprof handlers in dashboard listener.
# Dashboard port must be set first
pprof_enable = false

[plugin.user-manager]
addr = 127.0.0.1:9000
path = /handler
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ type ClientCommonConf struct {
UDPPacketSize int64 `ini:"udp_packet_size" json:"udp_packet_size"`
// Include other config files for proxies.
IncludeConfigFiles []string `ini:"includes" json:"includes"`
// Enable golang pprof handlers in admin listener.
// Admin port must be set first.
PprofEnable bool `ini:"pprof_enable" json:"pprof_enable"`
}

// GetDefaultClientConf returns a client configuration with default values.
Expand Down Expand Up @@ -188,6 +191,7 @@ func GetDefaultClientConf() ClientCommonConf {
Metas: make(map[string]string),
UDPPacketSize: 1500,
IncludeConfigFiles: make([]string, 0),
PprofEnable: false,
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ type ServerCommonConf struct {
// UDPPacketSize specifies the UDP packet size
// By default, this value is 1500
UDPPacketSize int64 `ini:"udp_packet_size" json:"udp_packet_size"`
// Enable golang pprof handlers in dashboard listener.
// Dashboard port must be set first.
PprofEnable bool `ini:"pprof_enable" json:"pprof_enable"`
}

// GetDefaultServerConf returns a server configuration with reasonable
Expand Down Expand Up @@ -210,6 +213,7 @@ func GetDefaultServerConf() ServerCommonConf {
Custom404Page: "",
HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
UDPPacketSize: 1500,
PprofEnable: false,
}
}

Expand Down
14 changes: 12 additions & 2 deletions server/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package server
import (
"net"
"net/http"
"net/http/pprof"
"time"

"github.com/fatedier/frp/assets"
Expand All @@ -27,15 +28,24 @@ import (
)

var (
httpServerReadTimeout = 10 * time.Second
httpServerWriteTimeout = 10 * time.Second
httpServerReadTimeout = 60 * time.Second
httpServerWriteTimeout = 60 * time.Second
)

func (svr *Service) RunDashboardServer(address string) (err error) {
// url router
router := mux.NewRouter()
router.HandleFunc("/healthz", svr.Healthz)

// debug
if svr.cfg.PprofEnable {
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
router.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index)
}

subRouter := router.NewRoute().Subrouter()

user, passwd := svr.cfg.DashboardUser, svr.cfg.DashboardPwd
Expand Down

0 comments on commit 63efa6b

Please sign in to comment.