summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2016-11-04 15:40:26 -0700
committerSteve Manuel <nilslice@gmail.com>2016-11-04 15:40:26 -0700
commit9c4a92c215153f7bca370396c9135eaebf0ab173 (patch)
tree0c02e80dfcfebff185d1b031027fda2ea45ca94a
parenteead663156d6b6cb300c96fcf90d3f804e4a5952 (diff)
keeping 2 weeks of data to show, pruning after 1 week, and testing date range UI on dahsboard
-rw-r--r--system/admin/admin.go3
-rw-r--r--system/api/analytics/init.go20
2 files changed, 19 insertions, 4 deletions
diff --git a/system/admin/admin.go b/system/admin/admin.go
index 27d8112..8c13582 100644
--- a/system/admin/admin.go
+++ b/system/admin/admin.go
@@ -373,6 +373,7 @@ var analyticsHTML = `
<div class="analytics">
<div class="card">
<div class="card-content">
+ <p class="right">Data range: {{ .from }} - {{ .to }}</p>
<div class="card-title">API Requests</div>
<canvas id="analytics-chart"></canvas>
<script>
@@ -421,7 +422,7 @@ var analyticsHTML = `
func Dashboard() ([]byte, error) {
buf := &bytes.Buffer{}
- data, err := analytics.Week()
+ data, err := analytics.ChartData()
if err != nil {
return nil, err
}
diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go
index 14eff7f..41c24c7 100644
--- a/system/api/analytics/init.go
+++ b/system/api/analytics/init.go
@@ -56,7 +56,7 @@ func Close() {
}
}
-// Init creates a db connection, should run an initial prune of old data, and
+// Init creates a db connection, initializes the db with schema and data and
// sets up the queue/batching channel
func Init() {
var err error
@@ -65,6 +65,18 @@ func Init() {
log.Fatalln(err)
}
+ err = store.Update(func(tx *bolt.Tx) error {
+ _, err := tx.CreateBucketIfNotExists([]byte("requests"))
+ if err != nil {
+ return err
+ }
+
+ return nil
+ })
+ if err != nil {
+ log.Fatalln("Error idempotently creating requests bucket in analytics.db:", err)
+ }
+
requestChan = make(chan apiRequest, 1024*64*runtime.NumCPU())
go serve()
@@ -105,8 +117,8 @@ func serve() {
}
}
-// Week returns the map containing decoded javascript needed to chart a week of data by day
-func Week() (map[string]interface{}, error) {
+// ChartData returns the map containing decoded javascript needed to chart 2 weeks of data by day
+func ChartData() (map[string]interface{}, error) {
// set thresholds for today and the 6 days preceeding
times := [14]time.Time{}
dates := [14]string{}
@@ -224,5 +236,7 @@ CHECK_REQUEST:
"dates": dates,
"unique": string(jsUnique),
"total": string(jsTotal),
+ "from": dates[0],
+ "to": dates[len(dates)-1],
}, nil
}