diff --git a/filters/filter.go b/filters/filter.go
new file mode 100644
index 0000000..5bd67bb
--- /dev/null
+++ b/filters/filter.go
@@ -0,0 +1,16 @@
+package filters
+
+import "github.com/flosch/pongo2"
+
+func init() {
+ pongo2.RegisterFilter("lastNItems", filterLastNItems)
+}
+
+func filterLastNItems(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
+ if !in.CanSlice() {
+ return in, nil
+ }
+
+ from := in.Len() - param.Integer()
+ return in.Slice(from, in.Len()), nil
+}
diff --git a/main.go b/main.go
index f0da838..c2a301a 100644
--- a/main.go
+++ b/main.go
@@ -13,6 +13,7 @@ import (
"github.com/flosch/pongo2"
"github.com/gorilla/mux"
+ _ "github.com/Luzifer/mondash/filters"
_ "github.com/flosch/pongo2-addons"
)
diff --git a/structs.go b/structs.go
index 353873b..d9aa5a1 100644
--- a/structs.go
+++ b/structs.go
@@ -166,27 +166,21 @@ func (dm *dashboardMetric) StatisticalStatus() string {
return "OK"
}
-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())) + ""
+func (dm *dashboardMetric) LabelHistory() []string {
+ s := []string{}
+ for _, v := range dm.HistoricalData[len(dm.HistoricalData)-60:] {
+ s = append(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)
+func (dm *dashboardMetric) DataHistory() []string {
+ s := []string{}
+ for _, v := range dm.HistoricalData[len(dm.HistoricalData)-60:] {
+ s = append(s, strconv.FormatFloat(v.Value, 'g', 4, 64))
}
- s = s + "]"
+
return s
}
diff --git a/templates/dashboard.html b/templates/dashboard.html
index 675e8c1..127a2eb 100644
--- a/templates/dashboard.html
+++ b/templates/dashboard.html
@@ -11,8 +11,8 @@
-
-
+
+