Skip to content

Commit

Permalink
remvove the code caculate the auto refresh time from probe, and add t…
Browse files Browse the repository at this point in the history
…he refresh parameter in URL (megaease#94)
  • Loading branch information
haoel committed May 18, 2022
1 parent 3df427d commit 115fdab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Check the [Notification Configuration](#37-notification-configuration) to see h

The EaseProbe would listen on the `0.0.0.0:8181` port by default. And you can access the Live SLA report by the following URL:

- HTML: `http:https://localhost:8181/`
- HTML: `http:https://localhost:8181/` or `http:https://localhost:8181/?refersh=30s`
- JSON: `http:https://localhost:8181/api/v1/sla`

Refer to the [Global Setting Configuration](#38-global-setting-configuration) to see how to configure the access log.
Expand Down
28 changes: 18 additions & 10 deletions web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"net"
"net/http"
"strconv"
"strings"
"time"

"github.com/megaease/easeprobe/conf"
"github.com/megaease/easeprobe/global"
Expand All @@ -35,8 +37,21 @@ import (

var probers *[]probe.Prober

func slaHTML(w http.ResponseWriter, req *http.Request) {
func getRefreshInterval(refersh string) time.Duration {
interval := conf.Get().Settings.HTTPServer.AutoRefreshTime
if strings.TrimSpace(refersh) == "" {
return interval
}
r, err := time.ParseDuration(refersh)
if err != nil {
log.Errorf("[Web] Invalid refresh time: %s", err)
return interval
}
return r
}

func slaHTML(w http.ResponseWriter, req *http.Request) {
interval := getRefreshInterval(req.URL.Query().Get("refresh"))
refresh := fmt.Sprintf("%d", interval.Milliseconds())
html := []byte(report.SLAHTML(*probers) + report.AutoRefreshJS(refresh))

Expand Down Expand Up @@ -75,16 +90,9 @@ func Server() {

// Configure the auto refresh time of the SLA page
if c.Settings.HTTPServer.AutoRefreshTime == 0 {
interval := global.DefaultProbeInterval
// find the minimum probe interval
for p := range *probers {
if interval > (*probers)[p].Interval() {
interval = (*probers)[p].Interval()
}
}
c.Settings.HTTPServer.AutoRefreshTime = interval
log.Debugf("[Web] Auto refresh interval time: %s", interval)
c.Settings.HTTPServer.AutoRefreshTime = global.DefaultProbeInterval
}
log.Debugf("[Web] Auto refresh interval time: %s", c.Settings.HTTPServer.AutoRefreshTime)

// Prepare the router
r := chi.NewRouter()
Expand Down

0 comments on commit 115fdab

Please sign in to comment.