Skip to content

Commit

Permalink
fix: add 95p and other stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pgagnidze committed Jan 3, 2024
1 parent acc3019 commit 8083840
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/gen2brain/beeep v0.0.0-20230907135156-1a38885a97fc
github.com/gizak/termui/v3 v3.1.0
github.com/mattn/go-runewidth v0.0.15
github.com/caio/go-tdigest/v4 v4.0.1
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/caio/go-tdigest/v4 v4.0.1 h1:sx4ZxjmIEcLROUPs2j1BGe2WhOtHD6VSe6NNbBdKYh4=
github.com/caio/go-tdigest/v4 v4.0.1/go.mod h1:Wsa+f0EZnV2gShdj1adgl0tQSoXRxtM0QioTgukFw8U=
github.com/gen2brain/beeep v0.0.0-20230907135156-1a38885a97fc h1:NNgdMgPX3j33uEAoVVxNxillDPnxT0xbGv8uh4CKIAo=
github.com/gen2brain/beeep v0.0.0-20230907135156-1a38885a97fc/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=
github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc=
Expand Down
Binary file modified images/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 62 additions & 7 deletions tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package tui

import (
"fmt"
"math"
"time"

"github.com/Owloops/updo/net"
"github.com/Owloops/updo/utils"
uw "github.com/Owloops/updo/widgets"

"github.com/caio/go-tdigest/v4"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)
Expand All @@ -19,11 +21,17 @@ type Manager struct {
StartTime time.Time
LastCheckTime time.Time
IsUp bool
MinResponseTime float64
MaxResponseTime float64
TDigest *tdigest.TDigest

QuitWidget *widgets.Paragraph
UptimeWidget *widgets.Paragraph
UpForWidget *widgets.Paragraph
AvgResponseTimeWidget *widgets.Paragraph
MinResponseTimeWidget *widgets.Paragraph
MaxResponseTimeWidget *widgets.Paragraph
P95ResponseTimeWidget *widgets.Paragraph
SSLOkWidget *widgets.Paragraph
UptimePlot *widgets.Plot
ResponseTimePlot *widgets.Plot
Expand All @@ -35,8 +43,14 @@ type Manager struct {
}

func NewManager() *Manager {
td, err := tdigest.New(tdigest.Compression(100))
if err != nil {
}
return &Manager{
StartTime: time.Now(),
StartTime: time.Now(),
MinResponseTime: math.MaxFloat64,
MaxResponseTime: 0,
TDigest: td,
}
}

Expand All @@ -57,10 +71,25 @@ func (m *Manager) InitializeWidgets(url string, refreshInterval time.Duration) {
m.UpForWidget.BorderStyle.Fg = ui.ColorBlue

m.AvgResponseTimeWidget = widgets.NewParagraph()
m.AvgResponseTimeWidget.Title = "Average Response Time"
m.AvgResponseTimeWidget.Title = "Average"
m.AvgResponseTimeWidget.Text = "N/A"
m.AvgResponseTimeWidget.BorderStyle.Fg = ui.ColorCyan

m.MinResponseTimeWidget = widgets.NewParagraph()
m.MinResponseTimeWidget.Title = "Min"
m.MinResponseTimeWidget.Text = "N/A"
m.MinResponseTimeWidget.BorderStyle.Fg = ui.ColorCyan

m.MaxResponseTimeWidget = widgets.NewParagraph()
m.MaxResponseTimeWidget.Title = "Max"
m.MaxResponseTimeWidget.Text = "N/A"
m.MaxResponseTimeWidget.BorderStyle.Fg = ui.ColorCyan

m.P95ResponseTimeWidget = widgets.NewParagraph()
m.P95ResponseTimeWidget.Title = "95p"
m.P95ResponseTimeWidget.Text = "N/A"
m.P95ResponseTimeWidget.BorderStyle.Fg = ui.ColorCyan

m.SSLOkWidget = widgets.NewParagraph()
m.SSLOkWidget.Title = "SSL Certificate"
m.SSLOkWidget.Text = "N/A"
Expand Down Expand Up @@ -113,17 +142,26 @@ func (m *Manager) InitializeWidgets(url string, refreshInterval time.Duration) {
ui.NewCol(1.0/4, m.QuitWidget),
),
ui.NewRow(1.0/7,
ui.NewCol(1.0/4, m.UptimeWidget),
ui.NewCol(1.0/4, m.AvgResponseTimeWidget),
ui.NewCol(1.0/4, m.AssertionWidget),
ui.NewCol(1.0/4, m.SSLOkWidget),
ui.NewCol(1.0/3, m.UptimeWidget),
ui.NewCol(1.0/3, m.AssertionWidget),
ui.NewCol(1.0/3, m.SSLOkWidget),
),
ui.NewRow(5.0/7,
ui.NewCol(3.0/5,
ui.NewRow(0.5, m.ResponseTimePlot),
ui.NewRow(0.5, m.UptimePlot),
),
ui.NewCol(2.0/5, ui.NewRow(1.0, m.TimingBreakdownWidget)),
ui.NewCol(2.0/5,
ui.NewRow(0.5/2,
ui.NewCol(1.0/2, m.MinResponseTimeWidget),
ui.NewCol(1.0/2, m.MaxResponseTimeWidget),
),
ui.NewRow(0.5/2,
ui.NewCol(1.0/2, m.AvgResponseTimeWidget),
ui.NewCol(1.0/2, m.P95ResponseTimeWidget),
),
ui.NewRow(1.0/2, m.TimingBreakdownWidget),
),
),
)
}
Expand All @@ -141,6 +179,23 @@ func (m *Manager) UpdateWidgets(result net.WebsiteCheckResult, width int, height
avgResponseTime := m.TotalResponseTime / time.Duration(m.ChecksCount)
m.AvgResponseTimeWidget.Text = utils.FormatDurationMillisecond(avgResponseTime)

if m.ChecksCount == 1 || result.ResponseTime < time.Duration(m.MinResponseTime) {
m.MinResponseTime = float64(result.ResponseTime)
}
if result.ResponseTime > time.Duration(m.MaxResponseTime) {
m.MaxResponseTime = float64(result.ResponseTime)
}

m.MinResponseTimeWidget.Text = utils.FormatDurationMillisecond(time.Duration(m.MinResponseTime))
m.MaxResponseTimeWidget.Text = utils.FormatDurationMillisecond(time.Duration(m.MaxResponseTime))

err := m.TDigest.Add(result.ResponseTime.Seconds())
if err != nil {
}

p95 := int(m.TDigest.Quantile(0.95) * 1000)
m.P95ResponseTimeWidget.Text = fmt.Sprintf("%d ms", p95)

sslExpiry := net.GetSSLCertExpiry(result.URL)
m.SSLOkWidget.Text = fmt.Sprintf("%d days remaining", sslExpiry)

Expand Down

0 comments on commit 8083840

Please sign in to comment.