-
Notifications
You must be signed in to change notification settings - Fork 88
/
server.go
49 lines (38 loc) · 1.03 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package supportbundle
import (
"fmt"
"net/http"
"runtime/pprof"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/logger"
)
func StartServer() {
go func() {
port := 3030
r := mux.NewRouter()
r.HandleFunc("/goroutines", getGoRoutines)
srv := &http.Server{
Handler: r,
Addr: fmt.Sprintf(":%d", port),
}
logger.Debugf("Starting supportbundle server on port %d...\n", port)
err := srv.ListenAndServe()
logger.Error(errors.Wrap(err, "failed to run support bundle server"))
}()
}
func getGoRoutines(w http.ResponseWriter, r *http.Request) {
profile := pprof.Lookup("goroutine")
if profile == nil {
logger.Errorf("failed to get goroutine info")
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set("Content-Disposition", "attachment; filename=goroutines.txt")
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
if err := profile.WriteTo(w, 2); err != nil {
logger.Error(errors.Wrap(err, "failed to get goroutine info"))
return
}
}