From 8a3cf7db088a4c7e75ff4acfcd41ffe98699f618 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 27 Mar 2016 20:32:53 +0200 Subject: [PATCH] Allow to use passed status instead of MAD --- apiary.apib | 1 + structs.go | 10 ++++++++++ templates/dashboard.html | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apiary.apib b/apiary.apib index 3c715b3..7fef653 100644 --- a/apiary.apib +++ b/apiary.apib @@ -72,6 +72,7 @@ This API controls the metrics on your dashboard + status (required, enum[string]) - One of: OK, Warning, Critical, Unknown + expires: 604800 (optional, number) - Time in seconds when to remove the metric if there is no update (Valid: `0 < x < 604800`) + freshness: 3600 (optional, number) - Time in seconds when to switch to `Unkown` state of there is no update (Valid: `0 < x < 604800`) + + ignore_mad: false (optional, boolean) - If set to true the status passed in the update will be used instead of the median absolute deviation + Response 200 (text/plain) diff --git a/structs.go b/structs.go index 6008b3a..4ee0625 100644 --- a/structs.go +++ b/structs.go @@ -61,6 +61,7 @@ type dashboardMetric struct { Value float64 `json:"value,omitifempty"` Expires int64 `json:"expires,omitifempty"` Freshness int64 `json:"freshness,omitifempty"` + IgnoreMAD bool `json:"ignore_mad"` HistoricalData dashboardMetricHistory `json:"history,omitifempty"` Meta dashboardMetricMeta `json:"meta,omitifempty"` } @@ -166,6 +167,14 @@ func (dm *dashboardMetric) StatisticalStatus() string { return "OK" } +func (dm *dashboardMetric) PreferredStatus() string { + if dm.IgnoreMAD { + return dm.Status + } + + return dm.StatisticalStatus() +} + func (dm *dashboardMetric) LabelHistory() []string { s := []string{} @@ -201,6 +210,7 @@ func (dm *dashboardMetric) Update(m *dashboardMetric) { dm.Description = m.Description dm.Status = m.Status dm.Value = m.Value + dm.IgnoreMAD = m.IgnoreMAD if m.Expires != 0 { dm.Expires = m.Expires } diff --git a/templates/dashboard.html b/templates/dashboard.html index 127a2eb..cac48a8 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -81,11 +81,11 @@ {% else %} {% for metric in metrics %} - {% if metric.StatisticalStatus == "OK" %} + {% if metric.PreferredStatus == "OK" %}
- {% elif metric.StatisticalStatus == "Warning" %} + {% elif metric.PreferredStatus == "Warning" %}
- {% elif metric.StatisticalStatus == "Critical" %} + {% elif metric.PreferredStatus == "Critical" %}
{% else %}