optimize link address setting for direct connect to remote plow (#8)
change description message in page optimize log delete link address flag
This commit is contained in:
parent
ccb0278500
commit
48dfe1f6c6
21
charts.go
21
charts.go
|
@ -4,16 +4,17 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
cors "github.com/AdhityaRamadhanus/fasthttpcors"
|
||||
"github.com/go-echarts/go-echarts/v2/charts"
|
||||
"github.com/go-echarts/go-echarts/v2/components"
|
||||
"github.com/go-echarts/go-echarts/v2/opts"
|
||||
"github.com/go-echarts/go-echarts/v2/templates"
|
||||
"github.com/valyala/fasthttp"
|
||||
"net"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -31,7 +32,7 @@ $(function () { setInterval({{ .ViewID }}_sync, {{ .Interval }}); });
|
|||
function {{ .ViewID }}_sync() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "http://{{ .Addr }}{{ .APIPath }}/{{ .Route }}",
|
||||
url: "{{ .APIPath }}/{{ .Route }}",
|
||||
dataType: "json",
|
||||
success: function (result) {
|
||||
let opt = goecharts_{{ .ViewID }}.getOption();
|
||||
|
@ -70,13 +71,11 @@ func (c *Charts) genViewTemplate(vid, route string) string {
|
|||
|
||||
var d = struct {
|
||||
Interval int
|
||||
Addr string
|
||||
APIPath string
|
||||
Route string
|
||||
ViewID string
|
||||
}{
|
||||
Interval: int(refreshInterval.Milliseconds()),
|
||||
Addr: c.linkAddr,
|
||||
APIPath: apiPath,
|
||||
Route: route,
|
||||
ViewID: vid,
|
||||
|
@ -139,23 +138,23 @@ type Metrics struct {
|
|||
|
||||
type Charts struct {
|
||||
listenAddr string
|
||||
linkAddr string
|
||||
page *components.Page
|
||||
ln net.Listener
|
||||
dataFunc func() *ChartsReport
|
||||
}
|
||||
|
||||
func NewCharts(listenAddr string, linkAddr string, dataFunc func() *ChartsReport, desc string) (*Charts, error) {
|
||||
func NewCharts(listenAddr string, dataFunc func() *ChartsReport, desc string) (*Charts, error) {
|
||||
templates.PageTpl = fmt.Sprintf(PageTpl, desc)
|
||||
ln, err := net.Listen("tcp4", listenAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c := &Charts{listenAddr: listenAddr, linkAddr: linkAddr, ln: ln, dataFunc: dataFunc}
|
||||
|
||||
c := &Charts{listenAddr: listenAddr, ln: ln, dataFunc: dataFunc}
|
||||
|
||||
c.page = components.NewPage()
|
||||
c.page.PageTitle = "plow"
|
||||
c.page.AssetsHost = fmt.Sprintf("http://%s%s", linkAddr, assertsPath)
|
||||
c.page.AssetsHost = assertsPath
|
||||
c.page.Assets.JSAssets.Add("jquery.min.js")
|
||||
c.page.AddCharts(c.newLatencyView(), c.newRPSView())
|
||||
|
||||
|
|
8
main.go
8
main.go
|
@ -24,7 +24,6 @@ var (
|
|||
contentType = kingpin.Flag("content", "Content-Type header").Short('T').String()
|
||||
|
||||
chartsListenAddr = kingpin.Flag("listen", "Listen addr to serve Web UI").Default(":18888").String()
|
||||
chartsLinkAddr = kingpin.Flag("link", "Link addr used for show Web html and request backend server").Default("127.0.0.1:18888").String()
|
||||
timeout = kingpin.Flag("timeout", "Timeout for each http request").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()
|
||||
|
@ -101,12 +100,7 @@ Example:
|
|||
desc += fmt.Sprintf(" for %s", duration.String())
|
||||
}
|
||||
desc += fmt.Sprintf(" using %d connection(s).", *concurrency)
|
||||
|
||||
fmt.Println(desc)
|
||||
if *chartsListenAddr != "" {
|
||||
fmt.Printf("@ Real-time charts is listening on http://%s/\n", *chartsLinkAddr)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
|
||||
requester, err := NewRequester(*concurrency, *requests, *duration, &clientOpt)
|
||||
if err != nil {
|
||||
|
@ -119,7 +113,7 @@ Example:
|
|||
go report.Collect(requester.RecordChan())
|
||||
|
||||
if *chartsListenAddr != "" {
|
||||
charts, err := NewCharts(*chartsListenAddr, *chartsLinkAddr, report.Charts, desc)
|
||||
charts, err := NewCharts(*chartsListenAddr, report.Charts, desc)
|
||||
if err != nil {
|
||||
errAndExit(err.Error())
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue