Hopefully shed some light on stats issue

This commit is contained in:
Calvin Montgomery 2013-07-17 22:55:50 -04:00
parent f4e392d190
commit d325d3126d
2 changed files with 16 additions and 6 deletions

2
acp.js
View File

@ -165,7 +165,7 @@ module.exports = function (Server) {
var db = Server.db.getConnection(); var db = Server.db.getConnection();
if(!db) if(!db)
return; return;
var query = "SELECT * FROM stats WHERE 1"; var query = "SELECT * FROM stats ORDER BY time ASC";
var results = db.querySync(query); var results = db.querySync(query);
if(results) if(results)
user.socket.emit("acp-view-stats", results.fetchAllSync()); user.socket.emit("acp-view-stats", results.fetchAllSync());

View File

@ -9,8 +9,12 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
var Logger = require("./logger");
const STAT_INTERVAL = 60 * 60 * 1000;
const STAT_EXPIRE = 24 * STAT_INTERVAL;
module.exports = function (Server) { module.exports = function (Server) {
// Check every 60 minutes
setInterval(function () { setInterval(function () {
var chancount = Server.channels.length; var chancount = Server.channels.length;
var usercount = 0; var usercount = 0;
@ -29,14 +33,20 @@ module.exports = function (Server) {
[Date.now(), usercount, chancount, mem] [Date.now(), usercount, chancount, mem]
); );
db.querySync(query); if(!db.querySync(query)) {
Logger.errlog.log("! Failed to record stats");
Logger.errlog.log(query);
}
query = Server.db.createQuery( query = Server.db.createQuery(
"DELETE FROM stats WHERE time<?", "DELETE FROM stats WHERE time<?",
[Date.now() - 24 * 60 * 60 * 1000] [Date.now() - STAT_EXPIRE]
); );
db.querySync(query); if(!db.querySync(query)) {
Logger.errlog.log("! Failed to prune stats");
Logger.errlog.log(query);
}
}, 60*60*1000); }, STAT_INTERVAL);
} }