Skip to content

Commit

Permalink
edgeview: do not forward tcp for pprof
Browse files Browse the repository at this point in the history
let the user of edgeview do it manually

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
  • Loading branch information
christoph-zededa authored and eriknordmark committed Jun 14, 2023
1 parent 9709bb0 commit 2f6675b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
4 changes: 3 additions & 1 deletion pkg/edgeview/src/basics.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func initOpts() {
"tcpdump",
"trace",
"url",
"pprof",
"wireless"}

pubsubopts = []string{
Expand Down Expand Up @@ -133,6 +132,7 @@ func initOpts() {
"techsupport",
"top",
"volume",
"pprof",
}

logdirectory = []string{
Expand Down Expand Up @@ -676,6 +676,8 @@ func printHelp(opt string) {
helpExample("cat/<path> -line <num>", "display only <num> of lines, like 'head' if <num> is positive, like 'tail' if the <num> is negative", false)
case "datastore":
helpOn("datastore", "display the device current datastore: EQDN, type, cipher information")
case "pprof":
helpOn("pprof", "pprof/on to turn on pprof; pprof/off to turn off again")
case "dmesg":
helpOn("dmesg", "display the device current dmesg information")
case "download":
Expand Down
7 changes: 0 additions & 7 deletions pkg/edgeview/src/edge-view.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,6 @@ func main() {
pnetopt = pqueryopt
} else if strings.HasPrefix(pqueryopt, "app") {
psysopt = pqueryopt
} else if pqueryopt == "pprof" {
var ok bool
ok, tcpclientCnt, remotePorts = processTCPcmd("tcp/localhost:6543", remotePorts)
if !ok {
return
}
pnetopt = pqueryopt
} else if strings.HasPrefix(pqueryopt, "tcp/") {
var ok bool
ok, tcpclientCnt, remotePorts = processTCPcmd(pqueryopt, remotePorts)
Expand Down
2 changes: 0 additions & 2 deletions pkg/edgeview/src/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ func runNetwork(netw string) {
runmDNS(substring)
} else if opt == "tcp" { // tcp and proxy are special
setAndStartProxyTCP(substring)
} else if opt == "pprof" {
runPprof()
} else if opt == "showcerts" {
getPeerCerts(substring)
} else if opt == "addhost" {
Expand Down
26 changes: 22 additions & 4 deletions pkg/edgeview/src/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"encoding/base64"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -96,6 +97,8 @@ func runSystem(cmds cmdOpt, sysOpt string) {
getDmesg()
} else if strings.HasPrefix(opt, "tar/") {
getTarFile(opt)
} else if strings.HasPrefix(opt, "pprof") {
togglePprof(opt)
} else {
fmt.Printf("opt %s: not supported yet\n", opt)
}
Expand Down Expand Up @@ -980,18 +983,33 @@ func dispAFile(f os.FileInfo) {
fmt.Printf("%s, %v, %d, %s\n", f.Mode().String(), f.ModTime(), f.Size(), f.Name())
}

func togglePprof(opt string) {
toggle := strings.SplitN(opt, "pprof/", 2)
if len(toggle) != 2 {
fmt.Printf("pprof needs to be either pprof/on or pprof/off\n")
return
}

if toggle[1] == "on" {
runPprof()
}
if toggle[1] == "off" {
stopPprof()
}
}

func runPprof() {
cmd := exec.Command("/usr/bin/pkill", "-USR2", "/opt/zededa/bin/zedbox")

err := cmd.Run()
if err != nil {
fmt.Printf("could not signal zedbox to run pprof")
}
}

setAndStartProxyTCP("localhost:6543")

_, err = http.Post("http://localhost:6543/stop", "", nil)
if err != nil {
func stopPprof() {
_, err := http.Post("http://localhost:6543/stop", "", nil)
if err != nil && !errors.Is(err, io.EOF) {
fmt.Printf("could not stop pprof: %+v\n", err)
}
}
Expand Down

0 comments on commit 2f6675b

Please sign in to comment.