mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-14 10:12:21 +00:00
tmp(memleak): temporary memleak measure to check avg response-time every 3mins. If >650ms (high mem) or ==0 (blackout), restart
This commit is contained in:
parent
56e2ec1bc4
commit
1ffb640833
2 changed files with 25 additions and 0 deletions
|
|
@ -17,6 +17,8 @@
|
|||
"STRIPE_API_KEY":"aaaabbbbccccddddeeeeffff00001111",
|
||||
"STRIPE_PUB_KEY":"22223333444455556666777788889999",
|
||||
"NEW_RELIC_LICENSE_KEY":"NEW_RELIC_LICENSE_KEY",
|
||||
"NEW_RELIC_APPLICATION_ID":"NEW_RELIC_APPLICATION_ID",
|
||||
"NEW_RELIC_API_KEY":"NEW_RELIC_API_KEY",
|
||||
"GA_ID": "GA_ID",
|
||||
"PAYPAL_USERNAME": "PAYPAL_USERNAME",
|
||||
"PAYPAL_PASSWORD": "PAYPAL_PASSWORD",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ var domainMiddleware = require('domain-middleware');
|
|||
var cluster = require('cluster');
|
||||
var i18n = require('./i18n.js');
|
||||
var shared = require('habitrpg-shared');
|
||||
var request = require('request');
|
||||
var moment = require('moment');
|
||||
|
||||
module.exports.apiThrottle = function(app) {
|
||||
if (nconf.get('NODE_ENV') !== 'production') return;
|
||||
|
|
@ -29,6 +31,27 @@ module.exports.apiThrottle = function(app) {
|
|||
}
|
||||
|
||||
module.exports.domainMiddleware = function(server,mongoose) {
|
||||
if (nconf.get('NODE_ENV')=='production') {
|
||||
var mins = 3;
|
||||
|
||||
//// Detect memory leak as high memory usage on the system. Tried this on prod for a few days, seems we can get blacked out even *without* memory being maxed.
|
||||
//setInterval(function(){
|
||||
// if (os.freemem() / os.totalmem() < 0.3) throw 'Memory leak';
|
||||
//}, mins*60*1000);
|
||||
|
||||
setInterval(function(){
|
||||
// see https://docs.newrelic.com/docs/apm/apis/api-v2-examples/average-response-time-examples-api-v2, https://rpm.newrelic.com/api/explore/applications/data
|
||||
request({
|
||||
//url: 'https://api.newrelic.com/v2/applications/APPLICATION_ID/metrics/data.json?names[]=HttpDispatcher&values[]=average_call_time&values[]=call_count&from=2014-10-14T2014-03-01T20:59:00+00:00:44:00+00:00&to=2014-10-14Tto=2014-03-01T21:59:00+00:00:14:00+00:00&summarize=true',
|
||||
url: 'https://api.newrelic.com/v2/applications/'+nconf.get('NEW_RELIC_APPLICATION_ID')+'/metrics/data.json?names[]=HttpDispatcher&values[]=average_response_time&from='+moment().subtract({minutes:mins}).utc().format()+'&to='+moment().utc().format()+'&summarize=true',
|
||||
headers: {'X-Api-Key': nconf.get('NEW_RELIC_API_KEY')}
|
||||
}, function(err, response, body){
|
||||
var avgResponseTime = JSON.parse(body).metric_data.metrics[0].timeslices[0].values.average_response_time;
|
||||
if (avgResponseTime > 650 || avgResponseTime == 0) throw 'Memory leak';
|
||||
})
|
||||
}, mins*60*1000);
|
||||
}
|
||||
|
||||
return domainMiddleware({
|
||||
server: {
|
||||
close:function(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue