From 7d7360c700b858f8ae8a9763b1199a8ea30078b0 Mon Sep 17 00:00:00 2001
From: Eugene Bujak <hmage@hmage.net>
Date: Wed, 3 Oct 2018 22:19:02 +0300
Subject: [PATCH 1/2] Web UI API -- Give out 24-hour stat instead of last 3
 minutes.

---
 client/src/components/Dashboard/BlockedDomains.js | 2 +-
 client/src/components/Dashboard/Clients.js        | 2 +-
 client/src/components/Dashboard/Counters.js       | 4 ++--
 client/src/components/Dashboard/QueriedDomains.js | 2 +-
 control.go                                        | 9 +++++----
 5 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/client/src/components/Dashboard/BlockedDomains.js b/client/src/components/Dashboard/BlockedDomains.js
index c6b039cc..4ede73c2 100644
--- a/client/src/components/Dashboard/BlockedDomains.js
+++ b/client/src/components/Dashboard/BlockedDomains.js
@@ -6,7 +6,7 @@ import map from 'lodash/map';
 import Card from '../ui/Card';
 
 const Clients = props => (
-    <Card title="Top blocked domains" subtitle="in the last 3 minutes" bodyType="card-table" refresh={props.refreshButton}>
+    <Card title="Top blocked domains" subtitle="in the last 24 hours" bodyType="card-table" refresh={props.refreshButton}>
         <ReactTable
             data={map(props.topBlockedDomains, (value, prop) => (
                 { ip: prop, domain: value }
diff --git a/client/src/components/Dashboard/Clients.js b/client/src/components/Dashboard/Clients.js
index 60419e42..220a0f67 100644
--- a/client/src/components/Dashboard/Clients.js
+++ b/client/src/components/Dashboard/Clients.js
@@ -6,7 +6,7 @@ import map from 'lodash/map';
 import Card from '../ui/Card';
 
 const Clients = props => (
-    <Card title="Top clients" subtitle="in the last 3 minutes" bodyType="card-table" refresh={props.refreshButton}>
+    <Card title="Top clients" subtitle="in the last 24 hours" bodyType="card-table" refresh={props.refreshButton}>
         <ReactTable
             data={map(props.topClients, (value, prop) => (
                 { ip: prop, count: value }
diff --git a/client/src/components/Dashboard/Counters.js b/client/src/components/Dashboard/Counters.js
index 094b78ed..44a9d188 100644
--- a/client/src/components/Dashboard/Counters.js
+++ b/client/src/components/Dashboard/Counters.js
@@ -5,13 +5,13 @@ import Card from '../ui/Card';
 import Tooltip from '../ui/Tooltip';
 
 const Counters = props => (
-    <Card title="General statistics" subtitle="in the last 3 minutes" bodyType="card-table" refresh={props.refreshButton}>
+    <Card title="General statistics" subtitle="in the last 24 hours" bodyType="card-table" refresh={props.refreshButton}>
         <table className="table card-table">
             <tbody>
                 <tr>
                     <td>
                         DNS Queries
-                        <Tooltip text="A number of DNS quieries processed in the last 3 minutes" />
+                        <Tooltip text="A number of DNS quieries processed in the last 24 hours" />
                     </td>
                     <td className="text-right">
                         <span className="text-muted">
diff --git a/client/src/components/Dashboard/QueriedDomains.js b/client/src/components/Dashboard/QueriedDomains.js
index a758d21b..f927e11a 100644
--- a/client/src/components/Dashboard/QueriedDomains.js
+++ b/client/src/components/Dashboard/QueriedDomains.js
@@ -6,7 +6,7 @@ import map from 'lodash/map';
 import Card from '../ui/Card';
 
 const QueriedDomains = props => (
-    <Card title="Top queried domains" subtitle="in the last 3 minutes" bodyType="card-table" refresh={props.refreshButton}>
+    <Card title="Top queried domains" subtitle="in the last 24 hours" bodyType="card-table" refresh={props.refreshButton}>
         <ReactTable
             data={map(props.topQueriedDomains, (value, prop) => (
                 { ip: prop, count: value }
diff --git a/control.go b/control.go
index cb6b1b6d..eae9975a 100644
--- a/control.go
+++ b/control.go
@@ -217,7 +217,7 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
 // stats
 // -----
 func handleStats(w http.ResponseWriter, r *http.Request) {
-	histrical := generateMapFromStats(&statistics.perMinute, 0, 2)
+	histrical := generateMapFromStats(&statistics.perHour, 0, 24)
 	// sum them up
 	summed := map[string]interface{}{}
 	for key, values := range histrical {
@@ -231,7 +231,7 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
 		}
 		summed[key] = summedValue
 	}
-	summed["stats_period"] = "3 minutes"
+	summed["stats_period"] = "24 hours"
 
 	json, err := json.Marshal(summed)
 	if err != nil {
@@ -439,7 +439,7 @@ func handleStatsTop(w http.ResponseWriter, r *http.Request) {
 	blocked := map[string]int{}
 	clients := map[string]int{}
 	now := time.Now()
-	timeWindow := time.Minute * 3
+	timeWindow := time.Hour * 24
 	notBefore := now.Add(timeWindow * -1)
 
 	for _, value := range values {
@@ -494,7 +494,8 @@ func handleStatsTop(w http.ResponseWriter, r *http.Request) {
 	}
 	gen(&json, "top_queried_domains", domains, true)
 	gen(&json, "top_blocked_domains", blocked, true)
-	gen(&json, "top_clients", clients, false)
+	gen(&json, "top_clients", clients, true)
+	json.WriteString("  \"stats_period\": \"24 hours\"\n")
 	json.WriteString("}\n")
 
 	w.Header().Set("Content-Type", "application/json")

From 57ade2c3c3804d24857a45a8ab31c10534154dc7 Mon Sep 17 00:00:00 2001
From: Eugene Bujak <hmage@hmage.net>
Date: Wed, 3 Oct 2018 22:25:55 +0300
Subject: [PATCH 2/2] Increase querylog size from 1000 to 10000 -- that'll use
 32MB of memory.

---
 coredns_plugin/querylog.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/coredns_plugin/querylog.go b/coredns_plugin/querylog.go
index a29388fb..3e2ae239 100644
--- a/coredns_plugin/querylog.go
+++ b/coredns_plugin/querylog.go
@@ -16,6 +16,8 @@ import (
 	"github.com/zfjagann/golang-ring"
 )
 
+const logBufferCap = 10000
+
 var logBuffer = ring.Ring{}
 
 type logEntry struct {
@@ -28,7 +30,7 @@ type logEntry struct {
 }
 
 func init() {
-	logBuffer.SetCapacity(1000)
+	logBuffer.SetCapacity(logBufferCap)
 }
 
 func logRequest(question *dns.Msg, answer *dns.Msg, result dnsfilter.Result, elapsed time.Duration, ip string) {