Update listen address
This commit is contained in:
parent
2a829ddbe8
commit
a8e3103636
16
charts.go
16
charts.go
|
@ -140,21 +140,15 @@ type Metrics struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Charts struct {
|
type Charts struct {
|
||||||
listenAddr string
|
page *components.Page
|
||||||
page *components.Page
|
ln net.Listener
|
||||||
ln net.Listener
|
dataFunc func() *ChartsReport
|
||||||
dataFunc func() *ChartsReport
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCharts(listenAddr string, dataFunc func() *ChartsReport, desc string) (*Charts, error) {
|
func NewCharts(ln net.Listener, dataFunc func() *ChartsReport, desc string) (*Charts, error) {
|
||||||
templates.PageTpl = fmt.Sprintf(PageTpl, desc)
|
templates.PageTpl = fmt.Sprintf(PageTpl, desc)
|
||||||
ln, err := net.Listen("tcp4", listenAddr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c := &Charts{listenAddr: listenAddr, ln: ln, dataFunc: dataFunc}
|
|
||||||
|
|
||||||
|
c := &Charts{ln: ln, dataFunc: dataFunc}
|
||||||
c.page = components.NewPage()
|
c.page = components.NewPage()
|
||||||
c.page.PageTitle = "plow"
|
c.page.PageTitle = "plow"
|
||||||
c.page.AssetsHost = assertsPath
|
c.page.AssetsHost = assertsPath
|
||||||
|
|
15
main.go
15
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ var (
|
||||||
host = kingpin.Flag("host", "Host header").String()
|
host = kingpin.Flag("host", "Host header").String()
|
||||||
contentType = kingpin.Flag("content", "Content-Type header").Short('T').String()
|
contentType = kingpin.Flag("content", "Content-Type header").Short('T').String()
|
||||||
|
|
||||||
chartsListenAddr = kingpin.Flag("listen", "Listen addr to serve Web UI").Default("0.0.0.0:18888").String()
|
chartsListenAddr = kingpin.Flag("listen", "Listen addr to serve Web UI").Default(":18888").String()
|
||||||
timeout = kingpin.Flag("timeout", "Timeout for each http request").PlaceHolder("DURATION").Duration()
|
timeout = kingpin.Flag("timeout", "Timeout for each http request").PlaceHolder("DURATION").Duration()
|
||||||
dialTimeout = kingpin.Flag("dial-timeout", "Timeout for dial addr").PlaceHolder("DURATION").Duration()
|
dialTimeout = kingpin.Flag("dial-timeout", "Timeout for dial addr").PlaceHolder("DURATION").Duration()
|
||||||
reqWriteTimeout = kingpin.Flag("req-timeout", "Timeout for full request writing").PlaceHolder("DURATION").Duration()
|
reqWriteTimeout = kingpin.Flag("req-timeout", "Timeout for full request writing").PlaceHolder("DURATION").Duration()
|
||||||
|
@ -102,8 +103,14 @@ Example:
|
||||||
desc += fmt.Sprintf(" using %d connection(s).", *concurrency)
|
desc += fmt.Sprintf(" using %d connection(s).", *concurrency)
|
||||||
fmt.Println(desc)
|
fmt.Println(desc)
|
||||||
|
|
||||||
|
var ln net.Listener
|
||||||
if *chartsListenAddr != "" {
|
if *chartsListenAddr != "" {
|
||||||
fmt.Printf("@ Real-time charts is listening on http://%s\n", *chartsListenAddr)
|
ln, err = net.Listen("tcp", *chartsListenAddr)
|
||||||
|
if err != nil {
|
||||||
|
errAndExit(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("@ Real-time charts is listening on http://%s\n", ln.Addr().String())
|
||||||
}
|
}
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
|
|
||||||
|
@ -117,8 +124,8 @@ Example:
|
||||||
report := NewStreamReport()
|
report := NewStreamReport()
|
||||||
go report.Collect(requester.RecordChan())
|
go report.Collect(requester.RecordChan())
|
||||||
|
|
||||||
if *chartsListenAddr != "" {
|
if ln != nil {
|
||||||
charts, err := NewCharts(*chartsListenAddr, report.Charts, desc)
|
charts, err := NewCharts(ln, report.Charts, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errAndExit(err.Error())
|
errAndExit(err.Error())
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue