mirror of
https://github.com/Luzifer/mondash.git
synced 2024-12-22 20:11:18 +00:00
Add statistical monitoring
This commit is contained in:
parent
e5da9e4c17
commit
525db95b08
2 changed files with 73 additions and 4 deletions
69
structs.go
69
structs.go
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"launchpad.net/goamz/s3"
|
||||
"log"
|
||||
"sort"
|
||||
"strconv"
|
||||
"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 {
|
||||
s := "["
|
||||
for i, v := range dm.HistoricalData {
|
||||
|
|
|
@ -81,11 +81,11 @@
|
|||
</div>
|
||||
{% else %}
|
||||
{% for metric in metrics %}
|
||||
{% if metric.Status == "OK" %}
|
||||
{% if metric.StatisticalStatus == "OK" %}
|
||||
<div class="row alert alert-success">
|
||||
{% elif metric.Status == "Warning" %}
|
||||
{% elif metric.StatisticalStatus == "Warning" %}
|
||||
<div class="row alert alert-warning">
|
||||
{% elif metric.Status == "Critical" %}
|
||||
{% elif metric.StatisticalStatus == "Critical" %}
|
||||
<div class="row alert alert-danger">
|
||||
{% else %}
|
||||
<div class="row alert alert-info">
|
||||
|
@ -93,7 +93,7 @@
|
|||
<div class="col-md-9">
|
||||
<h4>{{ metric.Title }}</h4>
|
||||
<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>
|
||||
<script>
|
||||
var data = {
|
||||
|
|
Loading…
Reference in a new issue