1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-12-23 04:21:18 +00:00

Add statistical monitoring

This commit is contained in:
zainhoda 2015-02-22 20:16:40 -05:00
parent e5da9e4c17
commit 525db95b08
2 changed files with 73 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import (
"errors" "errors"
"launchpad.net/goamz/s3" "launchpad.net/goamz/s3"
"log" "log"
"sort"
"strconv" "strconv"
"time" "time"
) )
@ -85,6 +86,74 @@ func newDashboardMetric() *dashboardMetric {
} }
} }
func median(values []float64) float64 {
sort.Float64s(values)
// If even, take an average
if len(values)%2 == 0 {
return 0.5*values[len(values)/2] + 0.5*values[len(values)/2-1]
}
return values[len(values)/2-1]
}
func absoluteValue(value float64) float64 {
if value < 0 {
value = -value
}
return value
}
func absoluteDeviation(values []float64) []float64 {
medianValue := median(values)
deviation := make([]float64, len(values))
for i, _ := range values {
deviation[i] = absoluteValue(values[i] - medianValue)
}
return deviation
}
func (dm *dashboardMetric) getValueArray() []float64 {
values := make([]float64, 0)
for _, v := range dm.HistoricalData {
values = append(values, v.Value)
}
return values
}
func (dm *dashboardMetric) Median() float64 {
return median(dm.getValueArray())
}
func (dm *dashboardMetric) MedianAbsoluteDeviation() (float64, float64) {
values := dm.getValueArray()
medianValue := dm.Median()
return medianValue, median(absoluteDeviation(values))
}
func (dm *dashboardMetric) MadMultiplier() float64 {
medianValue, MAD := dm.MedianAbsoluteDeviation()
return absoluteValue(dm.Value-medianValue) / MAD
}
func (dm *dashboardMetric) StatisticalStatus() string {
mult := dm.MadMultiplier()
if mult > 4 {
return "Critical"
} else if mult > 3 {
return "Warning"
}
return "OK"
}
func (dm *dashboardMetric) LabelHistory() string { func (dm *dashboardMetric) LabelHistory() string {
s := "[" s := "["
for i, v := range dm.HistoricalData { for i, v := range dm.HistoricalData {

View file

@ -81,11 +81,11 @@
</div> </div>
{% else %} {% else %}
{% for metric in metrics %} {% for metric in metrics %}
{% if metric.Status == "OK" %} {% if metric.StatisticalStatus == "OK" %}
<div class="row alert alert-success"> <div class="row alert alert-success">
{% elif metric.Status == "Warning" %} {% elif metric.StatisticalStatus == "Warning" %}
<div class="row alert alert-warning"> <div class="row alert alert-warning">
{% elif metric.Status == "Critical" %} {% elif metric.StatisticalStatus == "Critical" %}
<div class="row alert alert-danger"> <div class="row alert alert-danger">
{% else %} {% else %}
<div class="row alert alert-info"> <div class="row alert alert-info">
@ -93,7 +93,7 @@
<div class="col-md-9"> <div class="col-md-9">
<h4>{{ metric.Title }}</h4> <h4>{{ metric.Title }}</h4>
<p>{{ metric.Description }}</p> <p>{{ metric.Description }}</p>
<span class="label label-info">Current Value: {{ metric.Value }}</span> <span><span class="label label-info">Current Value: {{ metric.Value }}</span> {{ metric.MadMultiplier }} MAD above the Median ({{ metric.Median }})</span>
<div class="ct-chart {{metric.MetricID}} .ct-double-octave"></div> <div class="ct-chart {{metric.MetricID}} .ct-double-octave"></div>
<script> <script>
var data = { var data = {