mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
IMPROVEMENT: improve stats to not fill up memory over time 🎉
This commit is contained in:
@@ -1,25 +1,36 @@
|
|||||||
const config = require('../../conf/config.json');
|
const config = require('../../conf/config.json');
|
||||||
let lastScrape = {};
|
let stats = {
|
||||||
|
lastScrape: {},
|
||||||
|
foundScrapes: {}
|
||||||
|
};
|
||||||
|
|
||||||
if (config.enableStats) {
|
if (config.enableStats) {
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
http
|
http
|
||||||
.createServer((req, res) => {
|
.createServer((req, res) => {
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
res.writeHead(200, {'Content-Type': 'application/json'});
|
||||||
res.end(
|
res.end(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
config,
|
config,
|
||||||
lastScrape
|
stats
|
||||||
|
})
|
||||||
|
);
|
||||||
})
|
})
|
||||||
);
|
.listen(config.statsPort, '127.0.0.1');
|
||||||
})
|
|
||||||
.listen(config.statsPort, '127.0.0.1');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.setLastScrape = (serviceName, numberOfNewListsings) => {
|
const datetime = date => {
|
||||||
lastScrape[serviceName] = lastScrape[serviceName] || [];
|
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} ${date.getHours()}:${date.getMinutes()}`;
|
||||||
lastScrape[serviceName].push({
|
|
||||||
scapeTime: new Date().toString(),
|
|
||||||
listingsFound: numberOfNewListsings
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.setLastScrape = (serviceName, numberOfNewListsings) => {
|
||||||
|
const d = new Date();
|
||||||
|
const dt = datetime(d);
|
||||||
|
stats.lastScrape[serviceName] = d.toString();
|
||||||
|
|
||||||
|
if (numberOfNewListsings > 0) {
|
||||||
|
stats.foundScrapes[dt] = stats.foundScrapes[dt] || {};
|
||||||
|
stats.foundScrapes[dt][serviceName] = numberOfNewListsings;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user