Rework the oom notification

This commit is contained in:
Johannes Zellner
2019-01-08 14:20:08 +01:00
parent 07e052b865
commit 85ea9b3255
2 changed files with 12 additions and 9 deletions
+3 -5
View File
@@ -133,18 +133,16 @@ function processDockerEvents(intervalSecs, callback) {
stream.on('data', function (data) {
var ev = JSON.parse(data);
appdb.getByContainerId(ev.id, function (error, app) { // this can error for addons
var program = error || !app.appStoreId ? ev.id : app.appStoreId;
var context = JSON.stringify(ev);
var program = error || !app.id ? ev.id : `app-${app.id}`;
var now = Date.now();
if (app) context = context + '\n\n' + JSON.stringify(app, null, 4) + '\n';
const notifyUser = (!app || !app.debugMode) && (now - gLastOomMailTime > OOM_MAIL_LIMIT);
debug('OOM Context: %s. notifyUser: %s. lastOomTime: %s (now: %s)', context, notifyUser, gLastOomMailTime, now);
debug('OOM %s notifyUser: %s. lastOomTime: %s (now: %s)', program, notifyUser, gLastOomMailTime, now, ev);
// do not send mails for dev apps
if (notifyUser) {
notifications.oomEvent(program, context); // app can be null if it's an addon crash
notifications.oomEvent(program, { app: app || null, details: ev }); // app can be null if it's an addon crash
gLastOomMailTime = now;
}
});
+9 -4
View File
@@ -138,14 +138,19 @@ function userAdded(user, callback) {
function oomEvent(program, context, callback) {
assert.strictEqual(typeof program, 'string');
assert.strictEqual(typeof context, 'string');
assert.strictEqual(typeof context, 'object');
assert(typeof callback === 'undefined' || typeof callback === 'function');
callback = callback || NOOP_CALLBACK;
actionForAllAdmins(function (admin, callback) {
mailer.oomEvent(program, context);
add(admin.id, 'Process died out-of-memory', context, '', callback);
mailer.oomEvent(program, JSON.stringify(context, null, 4));
var message;
if (context.app) message = `The application ${context.app.manifest.title} with id ${context.app.id} ran out of memory.`;
else message = `The container with id ${context.details.id} ran out of memory`;
add(admin.id, 'Process died out-of-memory', message, context.app ? '/#/apps' : '', callback);
}, callback);
}
@@ -157,6 +162,6 @@ function appDied(app, callback) {
actionForAllAdmins(function (admin, callback) {
mailer.appDied(app);
add(admin.id, `App ${app.fqdn} died`, `The application ${app.manifest.title} installed at ${app.fqdn} is not responding.`, '', callback);
add(admin.id, `App ${app.fqdn} died`, `The application ${app.manifest.title} installed at ${app.fqdn} is not responding.`, '/#/apps', callback);
}, callback);
}