Skip to content

Commit 63efa6b

Browse files
authored
support pprof (fatedier#2849)
1 parent 37c2716 commit 63efa6b

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

client/admin.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package client
1717
import (
1818
"net"
1919
"net/http"
20+
"net/http/pprof"
2021
"time"
2122

2223
"github.com/fatedier/frp/assets"
@@ -26,8 +27,8 @@ import (
2627
)
2728

2829
var (
29-
httpServerReadTimeout = 10 * time.Second
30-
httpServerWriteTimeout = 10 * time.Second
30+
httpServerReadTimeout = 60 * time.Second
31+
httpServerWriteTimeout = 60 * time.Second
3132
)
3233

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

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

40+
// debug
41+
if svr.cfg.PprofEnable {
42+
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
43+
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
44+
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
45+
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
46+
router.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index)
47+
}
48+
3949
subRouter := router.NewRoute().Subrouter()
4050
user, passwd := svr.cfg.AdminUser, svr.cfg.AdminPwd
4151
subRouter.Use(frpNet.NewHTTPAuthMiddleware(user, passwd).Middleware)

conf/frpc_full.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ udp_packet_size = 1500
126126
# If DisableCustomTLSFirstByte is true, frpc will not send that custom byte.
127127
disable_custom_tls_first_byte = false
128128

129+
# Enable golang pprof handlers in admin listener.
130+
# Admin port must be set first.
131+
pprof_enable = false
132+
129133
# 'ssh' is the unique proxy name
130134
# if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh'
131135
[ssh]

conf/frps_full.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ tcp_mux = true
133133
# It affects the udp and sudp proxy.
134134
udp_packet_size = 1500
135135

136+
# Enable golang pprof handlers in dashboard listener.
137+
# Dashboard port must be set first
138+
pprof_enable = false
139+
136140
[plugin.user-manager]
137141
addr = 127.0.0.1:9000
138142
path = /handler

pkg/config/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ type ClientCommonConf struct {
151151
UDPPacketSize int64 `ini:"udp_packet_size" json:"udp_packet_size"`
152152
// Include other config files for proxies.
153153
IncludeConfigFiles []string `ini:"includes" json:"includes"`
154+
// Enable golang pprof handlers in admin listener.
155+
// Admin port must be set first.
156+
PprofEnable bool `ini:"pprof_enable" json:"pprof_enable"`
154157
}
155158

156159
// GetDefaultClientConf returns a client configuration with default values.
@@ -188,6 +191,7 @@ func GetDefaultClientConf() ClientCommonConf {
188191
Metas: make(map[string]string),
189192
UDPPacketSize: 1500,
190193
IncludeConfigFiles: make([]string, 0),
194+
PprofEnable: false,
191195
}
192196
}
193197

pkg/config/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ type ServerCommonConf struct {
167167
// UDPPacketSize specifies the UDP packet size
168168
// By default, this value is 1500
169169
UDPPacketSize int64 `ini:"udp_packet_size" json:"udp_packet_size"`
170+
// Enable golang pprof handlers in dashboard listener.
171+
// Dashboard port must be set first.
172+
PprofEnable bool `ini:"pprof_enable" json:"pprof_enable"`
170173
}
171174

172175
// GetDefaultServerConf returns a server configuration with reasonable
@@ -210,6 +213,7 @@ func GetDefaultServerConf() ServerCommonConf {
210213
Custom404Page: "",
211214
HTTPPlugins: make(map[string]plugin.HTTPPluginOptions),
212215
UDPPacketSize: 1500,
216+
PprofEnable: false,
213217
}
214218
}
215219

server/dashboard.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package server
1717
import (
1818
"net"
1919
"net/http"
20+
"net/http/pprof"
2021
"time"
2122

2223
"github.com/fatedier/frp/assets"
@@ -27,15 +28,24 @@ import (
2728
)
2829

2930
var (
30-
httpServerReadTimeout = 10 * time.Second
31-
httpServerWriteTimeout = 10 * time.Second
31+
httpServerReadTimeout = 60 * time.Second
32+
httpServerWriteTimeout = 60 * time.Second
3233
)
3334

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

40+
// debug
41+
if svr.cfg.PprofEnable {
42+
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
43+
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
44+
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
45+
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
46+
router.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index)
47+
}
48+
3949
subRouter := router.NewRoute().Subrouter()
4050

4151
user, passwd := svr.cfg.DashboardUser, svr.cfg.DashboardPwd

0 commit comments

Comments
 (0)