Skip to content

Commit fad36e4

Browse files
ChristophBodensteinChristophBodenstein
authored andcommitted
Stat updates are now triggered by timer.
Timed out simulations should be correct now.
1 parent cd15b5d commit fad36e4

File tree

1 file changed

+67
-66
lines changed
  • TOEDistributionServer/src/node/tns/routes

1 file changed

+67
-66
lines changed

TOEDistributionServer/src/node/tns/routes/index.js

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ var DEFAULT_SLEEPING_TIME = 5000;// in ms
2828
var DEFAULT_MINIMUM_TIMEOUT = 500;//in sec
2929

3030
setInterval(removeOldClientsFromList, 2000);
31+
setInterval(updateStats, 2000);
32+
3133
setInterval(function(){
3234
if(openSimulations==0){
3335
timeStampOfLastFinishedSimulation = Date.now();
@@ -44,67 +46,76 @@ var path=require('path');
4446
});
4547

4648

49+
/**
50+
* update all statistics
51+
*/
52+
function updateStats(){
53+
var db = global.db;
54+
var activeclients = db.collection('activeclients');
55+
var simlist = db.collection('simlist');
56+
57+
/*console.log("Delivering index-page.");*/
58+
simlist.find({simulated: false}, function (err, result) {
59+
if (err) {
60+
console.log("Error finding open simulations in db.");
61+
} else {
62+
//console.log("Will try to count open simulations.");
63+
if (result != null) {
64+
result.count(function (err, count){
65+
if(err){
66+
console.log("Error counting open simulations.");
67+
} else{
68+
openSimulations=count;
69+
//console.log("Number of open Simulations is:"+openSimulations);
70+
}
71+
});
72+
}
73+
}
74+
});
75+
76+
simlist.find({simulated: true}, function (err, result) {
77+
if (err) {
78+
console.log("Error finding done simulations in db.");
79+
} else{
80+
//console.log("Will try to count open simulations.");
81+
if (result != null) {
82+
result.count(function (err, count){
83+
if(err){
84+
console.log("Error counting done simulations.");
85+
} else {
86+
doneSimulations=count;
87+
}
88+
});
89+
}//End if
90+
}//End else
91+
});
92+
93+
//Check for timed out Simulations
94+
checkForTimedOutSimulations(simlist, function (err) {
95+
if (err) {
96+
console.log("Error checking for TimedOutSimulations.");
97+
}
98+
});
99+
}
47100

48101
router.get('/stats', function (req, res) {
49102
var db = req.db;
50103
var activeclients = db.collection('activeclients');
51104
var simlist = db.collection('simlist');
52105

53-
54-
/*console.log("Delivering index-page.");*/
55-
simlist.find({simulated: false}, function (err, result) {
56-
if (err) {
57-
console.log("Error finding open simulations in db.");
58-
} else {
59-
//console.log("Will try to count open simulations.");
60-
if (result != null) {
61-
result.count(function (err, count){
62-
if(err){
63-
console.log("Error counting open simulations.");
64-
} else{
65-
openSimulations=count;
66-
//console.log("Number of open Simulations is:"+openSimulations);
67-
68-
simlist.find({simulated: true}, function (err, result) {
69-
if (err) {
70-
console.log("Error finding done simulations in db.");
71-
} else {
72-
//console.log("Will try to count open simulations.");
73-
if (result != null) {
74-
result.count(function (err, count){
75-
if(err){
76-
console.log("Error counting done simulations.");
77-
} else {
78-
doneSimulations=count;
79-
//console.log("Number of done Simulations is:"+doneSimulations);
80-
81-
//removeOldClientsFromList(db, function (error) {
82-
res.render('stats', {
83-
title: 'TimeNET distribution server',
84-
clientcount: Math.round(global.clientcount),
85-
clientsrunning: global.clientsrunning,
86-
opensimulations: openSimulations.toLocaleString('de-DE', {maximumFractionDigits: 0}),
87-
donesimulations: doneSimulations.toLocaleString('de-DE', {maximumFractionDigits: 0}),
88-
percentagedone: ((doneSimulations *100)/(doneSimulations+openSimulations) || 0).toLocaleString('de-DE', {minimumFractionDigits: 2, maximumFractionDigits: 2}),
89-
averageSimulationsPerMinute: averageSimulationsPerMinute.toLocaleString('de-DE', {maximumFractionDigits: 1}),
90-
minutesToFinish: minutesToFinish.toLocaleString('de-DE', {maximumFractionDigits: 0}),
91-
timedOutSimulations: timedOutSimulations.toLocaleString('de-DE', {maximumFractionDigits: 0}),
92-
cpuUsage: cpuUsage,
93-
freeDiskSpace: freeDiskSpace
94-
95-
});
96-
97-
//});
98-
}
99-
});
100-
}//End if
101-
}//End else
102-
});
103-
}
104-
});
105-
}//End if
106-
}//End else
107-
});
106+
res.render('stats', {
107+
title: 'Server statistics',
108+
clientcount: Math.round(global.clientcount),
109+
opensimulations: openSimulations.toLocaleString('de-DE', {maximumFractionDigits: 0}),
110+
donesimulations: doneSimulations.toLocaleString('de-DE', {maximumFractionDigits: 0}),
111+
percentagedone: ((doneSimulations *100)/(doneSimulations+openSimulations) || 0).toLocaleString('de-DE', {minimumFractionDigits: 2, maximumFractionDigits: 2}),
112+
averageSimulationsPerMinute: averageSimulationsPerMinute.toLocaleString('de-DE', {maximumFractionDigits: 1}),
113+
minutesToFinish: minutesToFinish.toLocaleString('de-DE', {maximumFractionDigits: 0}),
114+
timedOutSimulations: timedOutSimulations.toLocaleString('de-DE', {maximumFractionDigits: 0}),
115+
cpuUsage: cpuUsage,
116+
freeDiskSpace: freeDiskSpace
117+
});
118+
108119
});
109120

110121

@@ -313,18 +324,7 @@ router.get('/rest/api/downloads/ND', function (req, res) {
313324
} else {
314325
}
315326
});
316-
317-
318-
319-
//Check for timed out Simulations
320-
checkForTimedOutSimulations(simlist, function (err) {
321-
if (err) {
322-
console.log("Error checking for TimedOutSimulations.");
323-
}
324-
});
325327
}
326-
327-
328328
}
329329

330330
});
@@ -361,6 +361,7 @@ function checkForTimedOutSimulations(simlist, cb) {
361361
console.log("Tim:" + localtimeout);
362362
console.log("------------------");*/
363363
if (localtimeout <= now) {
364+
timedOutSimulations=timedOutSimulations+1;
364365
//console.log("Try to reset entry to undistributed.");
365366
//set it to undistributed
366367
simlist.findAndModify(

0 commit comments

Comments
 (0)