diff --git a/backend/index.js b/backend/index.js
index 98ce947..1ef08f8 100644
--- a/backend/index.js
+++ b/backend/index.js
@@ -8,6 +8,7 @@ var systems = require("./controllers/systems");
var talkgroups = require("./controllers/talkgroups");
var groups = require("./controllers/groups");
var stats = require("./controllers/stats");
+var sys_stats = require("./sys_stats");
var events = require("./controllers/events");
var config = require('./config/config.json');
let db = require('./db')
@@ -134,6 +135,7 @@ app.get('/events/:id', events.getEvent);
/*------ STATS ----------*/
app.get('/:shortName/stats', stats.get_stats);
+app.get('/stats', sys_stats.siteStats)
function get_clients(req, res) {
diff --git a/backend/sys_stats.js b/backend/sys_stats.js
index bde70bc..490ef1a 100644
--- a/backend/sys_stats.js
+++ b/backend/sys_stats.js
@@ -9,12 +9,20 @@ var uploadErrors = {};
let decodeErrorsFreq = {};
const timePeriod = 15; // in minutes
var spots = (24 * 60) / timePeriod; // the number of spots needed to keep track of 24 hours of stats
+let uploadsPerMin = new Array(spots).fill(0);
+let activeSystems = 0;
+function updateUploadsPerMin(totalUploads) {
+ uploadsPerMin.push(totalUploads / timePeriod);
+ uploadsPerMin.shift();
+}
+
+
async function updateActiveSystems() {
// Go through all of the Systems
let siteTotal = 0;
- let activeSystems = 0;
+ activeSystems = 0;
for await (let item of System.find()) {
// go through all the systems
@@ -33,6 +41,7 @@ async function updateActiveSystems() {
await item.save();
};
+ updateUploadsPerMin(siteTotal);
console.log("Site average uploads per minute: " + siteTotal / timePeriod);
console.log("Active Systems: " + activeSystems);
}
@@ -324,6 +333,16 @@ exports.shiftStats = async function () {
updateActiveSystems();
console.log("Finished Updating Active Systems at: " + new Date());
}
+
+exports.siteStats = function() {
+ const siteStats ={
+ uploadsPerMin,
+ activeSystems
+ }
+ res.contentType('json');
+ res.send(JSON.stringify(siteStats));
+};
+
exports.callTotals = function (shortName) {
return callTotals[shortName];
}
diff --git a/frontend/src/Main/Main.js b/frontend/src/Main/Main.js
index 1d6f565..64269ad 100644
--- a/frontend/src/Main/Main.js
+++ b/frontend/src/Main/Main.js
@@ -21,7 +21,7 @@ import {
} from 'semantic-ui-react'
import { useDispatch } from 'react-redux'
-import { useGetSystemsQuery } from "../features/api/apiSlice";
+import { useGetStatsQuery, useGetSystemsQuery } from "../features/api/apiSlice";
/* Responsive component was removed from Semantic UI. This is discussed here: https://github.com/Semantic-Org/Semantic-UI-React/pull/4008 */
@@ -213,6 +213,86 @@ const ResponsiveContainer = ({ children }) => (
)
+
+import React from "react";
+import { Group } from '@visx/group';
+import { curveStep } from '@visx/curve';
+import { LinePath } from '@visx/shape';
+import { scaleLinear, scaleTime } from '@visx/scale';
+import { timeParse, timeFormat } from 'd3-time-format';
+import { AxisBottom, AxisLeft } from '@visx/axis';
+import { Loader } from "semantic-ui-react";
+
+const SiteStatsChart = ({ siteStats }) => {
+ if (!siteStats) {
+ return