add default.pgo in client &

added an option to enable pprof on client
This commit is contained in:
xtaci
2023-08-11 12:49:45 +08:00
parent 589fe49232
commit 55e670033b
3 changed files with 14 additions and 0 deletions
+1
View File
@@ -37,6 +37,7 @@ type Config struct {
SnmpPeriod int `json:"snmpperiod"`
Quiet bool `json:"quiet"`
TCP bool `json:"tcp"`
Pprof bool `json:"pprof"`
}
func parseJSONConfig(config *Config, path string) error {
Binary file not shown.
+13
View File
@@ -7,6 +7,8 @@ import (
"log"
"math/rand"
"net"
"net/http"
_ "net/http/pprof"
"os"
"time"
@@ -243,6 +245,10 @@ func main() {
Value: "", // when the value is not empty, the config path must exists
Usage: "config from json file, which will override the command from shell",
},
cli.BoolFlag{
Name: "pprof",
Usage: "start profiling server on :6060",
},
}
myApp.Action = func(c *cli.Context) error {
config := Config{}
@@ -276,6 +282,7 @@ func main() {
config.SnmpPeriod = c.Int("snmpperiod")
config.Quiet = c.Bool("quiet")
config.TCP = c.Bool("tcp")
config.Pprof = c.Bool("pprof")
if c.String("c") != "" {
err := parseJSONConfig(&config, c.String("c"))
@@ -341,6 +348,7 @@ func main() {
log.Println("snmpperiod:", config.SnmpPeriod)
log.Println("quiet:", config.Quiet)
log.Println("tcp:", config.TCP)
log.Println("pprof:", config.Pprof)
// parameters check
if config.SmuxVer > maxSmuxVer {
@@ -443,6 +451,11 @@ func main() {
// start snmp logger
go generic.SnmpLogger(config.SnmpLog, config.SnmpPeriod)
// start pprof
if config.Pprof {
go http.ListenAndServe(":6060", nil)
}
// start scavenger
chScavenger := make(chan timedSession, 128)
go scavenger(chScavenger, &config)