Files
fredy/lib/services/stats.js

36 lines
892 B
JavaScript
Raw Normal View History

2018-01-20 20:23:27 +01:00
const config = require('../../conf/config.json');
let stats = {
lastScrape: {},
foundScrapes: {}
};
2018-01-20 20:23:27 +01:00
if (config.enableStats) {
const http = require('http');
http
.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(
JSON.stringify({
config,
stats
2018-01-20 20:23:27 +01:00
})
);
})
.listen(config.statsPort, '127.0.0.1');
2018-01-20 20:23:27 +01:00
}
const datetime = date => {
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} ${date.getHours()}:${date.getMinutes()}`;
};
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;
}
2018-01-20 20:23:27 +01:00
};