Reports: among equal uptimes, the rows with something to say first #65
No files matched your search
+2
-1
@@ -699,7 +699,8 @@ older than 400 days is dropped.
|
||||
|
||||
The Reports page covers the last 7 or 30 days or any month: uptime per
|
||||
service, host and check (down is time critical, degraded time warning or
|
||||
serious), incidents people were told about with time to acknowledge and to
|
||||
serious; worst first, and among equal uptimes the most time down, then
|
||||
degraded, then incidents), incidents people were told about with time to acknowledge and to
|
||||
fix and a cause admins can write, certificates by expiry, disk use with a
|
||||
straight-line forecast of when each disk fills, CPU and memory per day,
|
||||
the mail monitor's rounds and block-list time, and backups. Every section
|
||||
|
||||
+23
-11
@@ -99,6 +99,26 @@ type Uptime struct {
|
||||
Incidents int `json:"incidents"`
|
||||
}
|
||||
|
||||
// worstFirst orders uptime rows by uptime, and among equals (most are
|
||||
// 100% when rounded) by time down, then degraded, then incidents, so the
|
||||
// rows worth reading aren't buried among quiet ones by name (#58).
|
||||
func worstFirst(l []Uptime) {
|
||||
sort.Slice(l, func(i, j int) bool {
|
||||
a, b := l[i], l[j]
|
||||
switch {
|
||||
case a.Pct != b.Pct:
|
||||
return a.Pct < b.Pct
|
||||
case a.DownS != b.DownS:
|
||||
return a.DownS > b.DownS
|
||||
case a.DegradedS != b.DegradedS:
|
||||
return a.DegradedS > b.DegradedS
|
||||
case a.Incidents != b.Incidents:
|
||||
return a.Incidents > b.Incidents
|
||||
}
|
||||
return a.Name < b.Name
|
||||
})
|
||||
}
|
||||
|
||||
// integrate adds up the time each entity spent in each status in [from, to).
|
||||
func integrate(changes []state.Change, from, to time.Time) map[string]*Uptime {
|
||||
by := map[string][]state.Change{}
|
||||
@@ -313,17 +333,9 @@ func (srv *Server) buildReport(from, to, now time.Time, label string) (*Report,
|
||||
r.Checks = append(r.Checks, *u)
|
||||
}
|
||||
}
|
||||
byPct := func(l []Uptime) {
|
||||
sort.Slice(l, func(i, j int) bool {
|
||||
if l[i].Pct != l[j].Pct {
|
||||
return l[i].Pct < l[j].Pct
|
||||
}
|
||||
return l[i].Name < l[j].Name
|
||||
})
|
||||
}
|
||||
byPct(r.Services)
|
||||
byPct(r.Hosts)
|
||||
byPct(r.Checks)
|
||||
worstFirst(r.Services)
|
||||
worstFirst(r.Hosts)
|
||||
worstFirst(r.Checks)
|
||||
|
||||
// Certificates, as they stand now.
|
||||
checks, _ := srv.judgeChecks(now)
|
||||
|
||||
@@ -179,3 +179,17 @@ func TestServerZone(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Among equal uptimes, the rows with something to say come first (#58).
|
||||
func TestWorstFirst(t *testing.T) {
|
||||
l := []Uptime{{Name: "a", Pct: 100}, {Name: "b", Pct: 100, Incidents: 220}, {Name: "c", Pct: 100, DegradedS: 60},
|
||||
{Name: "d", Pct: 99.5}, {Name: "e", Pct: 100, DownS: 30}, {Name: "f", Pct: -1}}
|
||||
worstFirst(l)
|
||||
var got []string
|
||||
for _, u := range l {
|
||||
got = append(got, u.Name)
|
||||
}
|
||||
if strings.Join(got, "") != "fdecba" {
|
||||
t.Errorf("order %v", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user