Browse Source

tweak request tracking

fix-133-memory-crash
Dan Janosik 6 years ago
parent
commit
7fd64e01d5
No known key found for this signature in database GPG Key ID: C6F8CE9FFDB2CED2
  1. 35
      app.js

35
app.js

@ -377,6 +377,11 @@ app.runOnStartup = function() {
setInterval(utils.logMemoryUsage, 5000);
};
app.use(function(req, res, next) {
req.start = Date.now();
next();
});
app.use(function(req, res, next) {
// make session available in templates
res.locals.session = req.session;
@ -394,15 +399,6 @@ app.use(function(req, res, next) {
}
}
if (global.influxdb) {
var points = [];
points.push({measurement:`express.request`, app:("btc-rpc-explorer." + global.config.coin), fields:{count:1, host:req.hostname, path:req.path, userAgent:userAgent}});
global.influxdb.writePoints(points).catch(err => {
console.error(`Error saving data to InfluxDB: ${err.stack}`);
});
}
res.locals.config = global.config;
res.locals.coinConfig = global.coinConfig;
@ -496,6 +492,27 @@ app.use(function(req, res, next) {
next();
});
app.use(function(req, res, next) {
var time = Date.now() - req.start;
console.log("time: " + time);
if (global.influxdb) {
var points = [];
points.push({
measurement:`express.request`,
tags:{app:("btc-rpc-explorer." + global.config.coin), host:req.hostname, path:req.path, userAgent:req.headers['user-agent']},
fields:{count:1, time:time}
});
global.influxdb.writePoints(points).catch(err => {
console.error(`Error saving data to InfluxDB: ${err.stack}`);
});
}
next();
});
app.use(csurf(), (req, res, next) => {
res.locals.csrfToken = req.csrfToken();
next();

Loading…
Cancel
Save