Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions cmd/wirey/main.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
package main

import (
"flag"
"log"
"net/http"
_ "net/http/pprof"
)

func main() {
enableProfiling := flag.Bool("enable-profiling", false, "Enable pprof profiling")
profileAddr := flag.String("profile-addr", "localhost:6060", "Address for pprof profiling")

flag.Parse()

if *enableProfiling {
go func() {
log.Printf("Starting pprof server on %s\n", *profileAddr)
if err := http.ListenAndServe(*profileAddr, nil); err != nil {
log.Fatalf("Error starting pprof server: %v\n", err)
}
}()
}

// Execute main application logic
Execute()
}
17 changes: 17 additions & 0 deletions cmd/wirey/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"math/rand"
"net"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -116,6 +118,17 @@ func backendFactory() (backend.Backend, error) {
httpBackend := viper.GetString("http")
//httpPortBackend := viper.GetInt("http-port")
discoverConf := viper.GetString("discover")
enableProfiling := viper.GetBool("enable-profiling")

if enableProfiling {
go func() {
profileAddr := viper.GetString("profile-addr")
log.Printf("Starting pprof server on %s\n", profileAddr)
if err := http.ListenAndServe(profileAddr, nil); err != nil {
log.Fatalf("Error starting pprof server: %v\n", err)
}
}()
}

// discover
discoverHosts := []string{}
Expand Down Expand Up @@ -237,6 +250,10 @@ func init() {
pflags.StringSlice("allowedips", nil, "array of allowed ips")
pflags.String("log-level", "info", "logging level to be used panic, fatal, error, trace, debug, warn, info")

// profiling flags
pflags.Bool("enable-profiling", false, "Enable pprof profiling")
pflags.String("profile-addr", "localhost:6060", "Address for pprof profiling")

rootCmd.MarkFlagRequired("endpoint")
rootCmd.MarkFlagRequired("ipaddr")

Expand Down