Skip to content

Commit

Permalink
feat: Support pprof when monitoring is specified (#1102)
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege authored and k8s-ci-robot committed Nov 27, 2019
1 parent 4926a28 commit 495b328
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion cmd/tf-operator.v1/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func (s *ServerOption) AddFlags(fs *flag.FlagSet) {
fs.StringVar(&s.GangSchedulerName, "gang-scheduler-name", "volcano", "The scheduler to gang-schedule tfjobs, defaults to volcano")

fs.IntVar(&s.MonitoringPort, "monitoring-port", 8443,
`Endpoint port for displaying monitoring metrics`)
`Endpoint port for displaying monitoring metrics.
It can be set to "0" to disable the metrics serving.`)

fs.DurationVar(&s.ResyncPeriod, "resyc-period", DefaultResyncPeriod, "Resync interval of the tf-operator")

fs.IntVar(&s.QPS, "qps", 5, "QPS indicates the maximum QPS to the master from this client.")
Expand Down
19 changes: 11 additions & 8 deletions cmd/tf-operator.v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"flag"
"fmt"
"net/http"
_ "net/http/pprof"
"strconv"

"github.com/onrik/logrus/filename"
Expand All @@ -36,14 +37,16 @@ func init() {
}

func startMonitoring(monitoringPort int) {
go func() {
log.Infof("Setting up client for monitoring on port: %s", strconv.Itoa(monitoringPort))
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(fmt.Sprintf(":%s", strconv.Itoa(monitoringPort)), nil)
if err != nil {
log.Error("Monitoring endpoint setup failure.")
}
}()
if monitoringPort != 0 {
go func() {
log.Infof("Setting up client for monitoring on port: %s", strconv.Itoa(monitoringPort))
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(fmt.Sprintf(":%s", strconv.Itoa(monitoringPort)), nil)
if err != nil {
log.Error("Monitoring endpoint setup failure.", err)
}
}()
}
}

func main() {
Expand Down

0 comments on commit 495b328

Please sign in to comment.