github.com/erda-project/erda-infra@v1.0.9/providers/pprof/provider.go (about) 1 // Copyright (c) 2021 Terminus, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package pprof 16 17 import ( 18 "net/http" 19 "net/http/pprof" 20 21 "github.com/erda-project/erda-infra/base/servicehub" 22 "github.com/erda-project/erda-infra/providers/httpserver" 23 ) 24 25 // provider . 26 type provider struct { 27 server *http.Server 28 Router httpserver.Router `autowired:"http-server@admin"` 29 } 30 31 // Init . 32 func (p *provider) Init(ctx servicehub.Context) error { 33 mux := http.NewServeMux() 34 mux.HandleFunc("/debug/pprof/", pprof.Index) 35 mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) 36 mux.HandleFunc("/debug/pprof/profile", pprof.Profile) 37 mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) 38 mux.HandleFunc("/debug/pprof/trace", pprof.Trace) 39 40 p.Router.Any("/debug/pprof/**", mux) 41 return nil 42 } 43 44 func init() { 45 servicehub.Register("pprof", &servicehub.Spec{ 46 Services: []string{"pprof"}, 47 Dependencies: []string{"http-server"}, 48 Description: "start pprof http server", 49 Creator: func() servicehub.Provider { return &provider{} }, 50 }) 51 }