From dd8ce13eaf39117da370a5a18eacbd528b864d0c Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 8 Feb 2015 09:16:32 +0100 Subject: [PATCH] Do not show expired metrics --- main.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 965bfdc..e5a600f 100644 --- a/main.go +++ b/main.go @@ -60,10 +60,19 @@ func main() { if err != nil { dash = &Dashboard{APIKey: generateAPIKey(), Metrics: DashboardMetrics{}} } - sort.Sort(sort.Reverse(DashboardMetrics(dash.Metrics))) + + // Filter out expired metrics + metrics := DashboardMetrics{} + for _, m := range dash.Metrics { + if m.Meta.LastUpdate.After(time.Now().Add(time.Duration(m.Expires*-1) * time.Second)) { + metrics = append(metrics, m) + } + } + + sort.Sort(sort.Reverse(DashboardMetrics(metrics))) renderTemplate("dashboard.html", pongo2.Context{ "dashid": params["dashid"], - "metrics": dash.Metrics, + "metrics": metrics, "apikey": dash.APIKey, "baseurl": os.Getenv("BASE_URL"), }, res)