1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-12-22 20:11:18 +00:00

Add "value" as an option and basic graphing capabilities

This commit is contained in:
zainhoda 2015-02-22 15:58:58 -05:00
parent 84297ff0a6
commit 740ac28ce6
2 changed files with 49 additions and 3 deletions

View file

@ -3,10 +3,10 @@ package main
import (
"encoding/json"
"errors"
"log"
"time"
"launchpad.net/goamz/s3"
"log"
"strconv"
"time"
)
type dashboard struct {
@ -52,6 +52,7 @@ type dashboardMetric struct {
Title string `json:"title"`
Description string `json:"description"`
Status string `json:"status"`
Value float64 `json:"value,omitifempty"`
Expires int64 `json:"expires,omitifempty"`
Freshness int64 `json:"freshness,omitifempty"`
HistoricalData dashboardMetricHistory `json:"history,omitifempty"`
@ -61,6 +62,7 @@ type dashboardMetric struct {
type dashboardMetricStatus struct {
Time time.Time `json:"time"`
Status string `json:"status"`
Value float64 `json:"value"`
}
type dashboardMetricMeta struct {
@ -83,10 +85,35 @@ func newDashboardMetric() *dashboardMetric {
}
}
func (dm *dashboardMetric) LabelHistory() string {
s := "["
for i, v := range dm.HistoricalData {
if i != 0 {
s = s + ", "
}
s = s + "" + strconv.Itoa(int(v.Time.Unix())) + ""
}
s = s + "]"
return s
}
func (dm *dashboardMetric) DataHistory() string {
s := "["
for i, v := range dm.HistoricalData {
if i != 0 {
s = s + ", "
}
s = s + strconv.FormatFloat(v.Value, 'g', 4, 64)
}
s = s + "]"
return s
}
func (dm *dashboardMetric) Update(m *dashboardMetric) {
dm.Title = m.Title
dm.Description = m.Description
dm.Status = m.Status
dm.Value = m.Value
if m.Expires != 0 {
dm.Expires = m.Expires
}
@ -96,6 +123,7 @@ func (dm *dashboardMetric) Update(m *dashboardMetric) {
dm.HistoricalData = append(dashboardMetricHistory{dashboardMetricStatus{
Time: time.Now(),
Status: m.Status,
Value: m.Value,
}}, dm.HistoricalData...)
countStatus := make(map[string]float64)

View file

@ -10,6 +10,10 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
<!-- Chartist Library -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
<script src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
@ -75,6 +79,20 @@
<div class="col-md-9">
<h4>{{ metric.Title }}</h4>
<p>{{ metric.Description }}</p>
<span class="label label-info">Current Value: {{ metric.Value }}</span>
<div class="ct-chart {{metric.MetricID}} .ct-double-octave"></div>
<script>
var data = {
// A labels array that can contain any sort of values
labels: {{ metric.LabelHistory }},
// Our series array that contains series objects or in this case series data arrays
series: [
{{ metric.DataHistory }}
]
};
new Chartist.Line('.{{metric.MetricID}}', data);
</script>
<small>
Updated {{ metric.Meta.LastUpdate|naturaltime}}
{% if metric.Status != "OK" %}