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"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
cors "github.com/AdhityaRamadhanus/fasthttpcors"
|
cors "github.com/AdhityaRamadhanus/fasthttpcors"
|
||||||
"github.com/go-echarts/go-echarts/v2/charts"
|
"github.com/go-echarts/go-echarts/v2/charts"
|
||||||
"github.com/go-echarts/go-echarts/v2/components"
|
"github.com/go-echarts/go-echarts/v2/components"
|
||||||
"github.com/go-echarts/go-echarts/v2/opts"
|
"github.com/go-echarts/go-echarts/v2/opts"
|
||||||
"github.com/go-echarts/go-echarts/v2/templates"
|
"github.com/go-echarts/go-echarts/v2/templates"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
"net"
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -31,7 +32,7 @@ $(function () { setInterval({{ .ViewID }}_sync, {{ .Interval }}); });
|
||||||
function {{ .ViewID }}_sync() {
|
function {{ .ViewID }}_sync() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: "http://{{ .Addr }}{{ .APIPath }}/{{ .Route }}",
|
url: "{{ .APIPath }}/{{ .Route }}",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
let opt = goecharts_{{ .ViewID }}.getOption();
|
let opt = goecharts_{{ .ViewID }}.getOption();
|
||||||
|
@ -70,13 +71,11 @@ func (c *Charts) genViewTemplate(vid, route string) string {
|
||||||
|
|
||||||
var d = struct {
|
var d = struct {
|
||||||
Interval int
|
Interval int
|
||||||
Addr string
|
|
||||||
APIPath string
|
APIPath string
|
||||||
Route string
|
Route string
|
||||||
ViewID string
|
ViewID string
|
||||||
}{
|
}{
|
||||||
Interval: int(refreshInterval.Milliseconds()),
|
Interval: int(refreshInterval.Milliseconds()),
|
||||||
Addr: c.linkAddr,
|
|
||||||
APIPath: apiPath,
|
APIPath: apiPath,
|
||||||
Route: route,
|
Route: route,
|
||||||
ViewID: vid,
|
ViewID: vid,
|
||||||
|
@ -139,23 +138,23 @@ type Metrics struct {
|
||||||
|
|
||||||
type Charts struct {
|
type Charts struct {
|
||||||
listenAddr string
|
listenAddr string
|
||||||
linkAddr string
|
|
||||||
page *components.Page
|
page *components.Page
|
||||||
ln net.Listener
|
ln net.Listener
|
||||||
dataFunc func() *ChartsReport
|
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)
|
templates.PageTpl = fmt.Sprintf(PageTpl, desc)
|
||||||
ln, err := net.Listen("tcp4", listenAddr)
|
ln, err := net.Listen("tcp4", listenAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 = components.NewPage()
|
||||||
c.page.PageTitle = "plow"
|
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.Assets.JSAssets.Add("jquery.min.js")
|
||||||
c.page.AddCharts(c.newLatencyView(), c.newRPSView())
|
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()
|
contentType = kingpin.Flag("content", "Content-Type header").Short('T').String()
|
||||||
|
|
||||||
chartsListenAddr = kingpin.Flag("listen", "Listen addr to serve Web UI").Default(":18888").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()
|
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()
|
||||||
|
@ -101,12 +100,7 @@ Example:
|
||||||
desc += fmt.Sprintf(" for %s", duration.String())
|
desc += fmt.Sprintf(" for %s", duration.String())
|
||||||
}
|
}
|
||||||
desc += fmt.Sprintf(" using %d connection(s).", *concurrency)
|
desc += fmt.Sprintf(" using %d connection(s).", *concurrency)
|
||||||
|
|
||||||
fmt.Println(desc)
|
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)
|
requester, err := NewRequester(*concurrency, *requests, *duration, &clientOpt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -119,7 +113,7 @@ Example:
|
||||||
go report.Collect(requester.RecordChan())
|
go report.Collect(requester.RecordChan())
|
||||||
|
|
||||||
if *chartsListenAddr != "" {
|
if *chartsListenAddr != "" {
|
||||||
charts, err := NewCharts(*chartsListenAddr, *chartsLinkAddr, report.Charts, desc)
|
charts, err := NewCharts(*chartsListenAddr, report.Charts, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errAndExit(err.Error())
|
errAndExit(err.Error())
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue