aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2019-04-06 15:27:13 -0400
committerMark Powers <markppowers0@gmail.com>2019-04-06 15:27:13 -0400
commit7d0aa00e74b1ed2ea2cab9afaf8eb7b7f9280d3d (patch)
tree73ce87ec71409573e9c1d508c696caa8ba5c24a7
parentfd40608784ad428822e7c3ea02d35bca196966fd (diff)
Filter sessions in admin
-rw-r--r--package-lock.json10
-rw-r--r--package.json4
-rw-r--r--src/html/admin.html40
-rw-r--r--src/server.js5
4 files changed, 32 insertions, 27 deletions
diff --git a/package-lock.json b/package-lock.json
index 17a85b3..53fe687 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -102,11 +102,6 @@
"type-is": "~1.6.16"
}
},
- "bootstrap": {
- "version": "4.1.3",
- "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.1.3.tgz",
- "integrity": "sha512-rDFIzgXcof0jDyjNosjv4Sno77X4KuPeFxG2XZZv1/Kc8DRVGVADdoQyyOVDwPqL36DDmtCQbrpMCqvpPLJQ0w=="
- },
"buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
@@ -1144,11 +1139,6 @@
"extsprintf": "^1.2.0"
}
},
- "vue": {
- "version": "2.5.22",
- "resolved": "https://registry.npmjs.org/vue/-/vue-2.5.22.tgz",
- "integrity": "sha512-pxY3ZHlXNJMFQbkjEgGVMaMMkSV1ONpz+4qB55kZuJzyJOhn6MSy/YZdzhdnumegNzVTL/Dn3Pp4UrVBYt1j/g=="
- },
"wkx": {
"version": "0.4.6",
"resolved": "https://registry.npmjs.org/wkx/-/wkx-0.4.6.tgz",
diff --git a/package.json b/package.json
index 7538b7e..324ba7c 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,6 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
- "bootstrap": "^4.1.3",
"cookie-parser": "^1.4.3",
"express": "^4.16.4",
"jsonwebtoken": "^8.4.0",
@@ -19,7 +18,6 @@
"mysql2": "^1.6.4",
"request": "^2.88.0",
"sequelize": "^4.42.0",
- "uuid": "^3.3.2",
- "vue": "^2.5.22"
+ "uuid": "^3.3.2"
}
}
diff --git a/src/html/admin.html b/src/html/admin.html
index 1087b51..01a39b4 100644
--- a/src/html/admin.html
+++ b/src/html/admin.html
@@ -13,7 +13,7 @@
var feed = new Vue({
el: '#stats',
data: {
- stats: {session: [], url: []},
+ stats: { session: [], url: [] },
showSessionTable: false,
showUrlTable: false,
showLogData: false,
@@ -33,10 +33,10 @@
<div class="form">
<form action="/posts" method="post" enctype="multipart/form-data">
<div>
- <textarea name="description"></textarea>
+ <textarea name="description"></textarea>
</div>
<div>
- <span>Tags: <input type="text" name="tags"/></span>
+ <span>Tags: <input type="text" name="tags" /></span>
</div>
<div>
Images: <input type="file" name="images" multiple>
@@ -47,7 +47,7 @@
<option value="bread">Bread</option>
<option value="blog">Blog</option>
<option value="index">Index</option>
- </select>
+ </select>
</div>
<input type="submit" value="Submit">
</form>
@@ -59,18 +59,29 @@
<input type="checkbox" id="showSession" v-model="showSessionTable">
<label for="showSession">Show Session Stats</label>
</div>
- <table class="table session-table" v-if="showSessionTable">
- <tr><th>Host</th><th>Total Requests</th></tr>
- <tr v-for="item in stats.session">
- <td>{{item.session.substring(0,10)}}...</td><td>{{item.c}}</td>
- </tr>
- </table>
+ <div v-if="showSessionTable">
+ {{stats.total}} total sessions
+ <table class="table session-table">
+ <tr>
+ <th>Host</th>
+ <th>Total Requests</th>
+ </tr>
+ <tr v-for="item in stats.session">
+ <td>{{item.session.substring(0,10)}}...</td>
+ <td>{{item.c}}</td>
+ </tr>
+ </table>
+ </div>
<div>
<input type="checkbox" id="showUrl" v-model="showUrlTable">
<label for="showUrl">Show URL Stats</label>
</div>
<table class="table url-table" v-if="showUrlTable">
- <tr><th>Method</th><th>Path</th><th>Total Requests</th></tr>
+ <tr>
+ <th>Method</th>
+ <th>Path</th>
+ <th>Total Requests</th>
+ </tr>
<tr v-for="item in stats.url">
<td>{{item.method}}</td>
<td>{{item.url.substring(0, Math.min(30, item.url.length))}}</td>
@@ -82,7 +93,12 @@
<label for="showLog">Show Log</label>
</div>
<table class="table log-table" v-if="showLogData">
- <tr><th>Date</th><th>Session</th><th>Method</th><th>Path</th></tr>
+ <tr>
+ <th>Date</th>
+ <th>Session</th>
+ <th>Method</th>
+ <th>Path</th>
+ </tr>
<tr v-for="item in stats.log">
<td>{{item.createdAt.substring(0,19)}}</td>
<td>{{item.session.substring(0,10)}}...</td>
diff --git a/src/server.js b/src/server.js
index 06a3ec5..eae99e4 100644
--- a/src/server.js
+++ b/src/server.js
@@ -96,10 +96,11 @@ function setUpRoutes(models, jwtFunctions, database) {
})
server.get('/admin/stats', async (req, res, next) => {
try {
- var sessionResult = await database.query("SELECT session, count(id) as c FROM requests GROUP BY session", { type: database.QueryTypes.SELECT })
+ var sessionResult = await database.query("SELECT session, count(id) as c FROM requests GROUP BY session HAVING c > 1", { type: database.QueryTypes.SELECT })
+ var total = await database.query("select count(distinct session) as t FROM requests", { type: database.QueryTypes.SELECT })
var urlResult = await database.query("SELECT method, url, count(id) as c FROM requests GROUP BY method, url", { type: database.QueryTypes.SELECT })
var logResult = await database.query("SELECT createdAt, session, method, url FROM requests order by createdAt desc limit 15", { type: database.QueryTypes.SELECT })
- res.status(200).send({ session: sessionResult, url: urlResult, log: logResult });
+ res.status(200).send({ total: total[0].t, session: sessionResult, url: urlResult, log: logResult });
next();
} catch (e) {
res.status(400).send(e.message);