|
@@ -3,6 +3,7 @@ package controller
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
+ "os"
|
|
"strings"
|
|
"strings"
|
|
"syscall"
|
|
"syscall"
|
|
"time"
|
|
"time"
|
|
@@ -17,6 +18,8 @@ import (
|
|
"github.com/gravitl/netmaker/servercfg"
|
|
"github.com/gravitl/netmaker/servercfg"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+var cpuProfileLog *os.File
|
|
|
|
+
|
|
func serverHandlers(r *mux.Router) {
|
|
func serverHandlers(r *mux.Router) {
|
|
// r.HandleFunc("/api/server/addnetwork/{network}", securityCheckServer(true, http.HandlerFunc(addNetwork))).Methods(http.MethodPost)
|
|
// r.HandleFunc("/api/server/addnetwork/{network}", securityCheckServer(true, http.HandlerFunc(addNetwork))).Methods(http.MethodPost)
|
|
r.HandleFunc(
|
|
r.HandleFunc(
|
|
@@ -43,6 +46,21 @@ func serverHandlers(r *mux.Router) {
|
|
r.HandleFunc("/api/server/status", getStatus).Methods(http.MethodGet)
|
|
r.HandleFunc("/api/server/status", getStatus).Methods(http.MethodGet)
|
|
r.HandleFunc("/api/server/usage", logic.SecurityCheck(false, http.HandlerFunc(getUsage))).
|
|
r.HandleFunc("/api/server/usage", logic.SecurityCheck(false, http.HandlerFunc(getUsage))).
|
|
Methods(http.MethodGet)
|
|
Methods(http.MethodGet)
|
|
|
|
+ r.HandleFunc("/api/server/cpu_profile", cpuProfile).
|
|
|
|
+ Methods(http.MethodPost)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func cpuProfile(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ start := r.URL.Query().Get("action") == "start"
|
|
|
|
+ if start {
|
|
|
|
+ os.Remove("/root/data/cpu.prof")
|
|
|
|
+ cpuProfileLog = logic.StartCPUProfiling()
|
|
|
|
+ } else {
|
|
|
|
+ if cpuProfileLog != nil {
|
|
|
|
+ logic.StopCPUProfiling(cpuProfileLog)
|
|
|
|
+ cpuProfileLog = nil
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func getUsage(w http.ResponseWriter, _ *http.Request) {
|
|
func getUsage(w http.ResponseWriter, _ *http.Request) {
|