mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 15:45:01 -05:00
A developer laptop with many programs open showed in Admin Panel / Problems / Memory usage: "RamBleed, high, high RAM usage started (>= 90%): RAM 16.1/30.9 GB (52%), swap 18.7/30.9 GB (60%)". Swap at or above 25% started a high-memory period by itself, made it high severity, and the text still said ">= 90%". Idle pages in swap while RAM is free are not pressure. - Swap now counts only while RAM is also at or above the low threshold (80%), and a period ends when RAM is back under it. - The start row says what started it: (RAM >= 90%) or (swap >= 25% with RAM >= 80%). Only RAM at 95% or more is high severity. - The RAM, CPU, disk and speed monitors named their rows like Hall of Fame entries (RamBleed, CpuBleed, DiskBleed, SlowBleed) with CWE-400. They are HighRamUsage, HighCpuUsage, HighDiskUsage and SlowRequest now, without a CWE, and stored rows are renamed once at startup. tests/ramHighTracker.test.cjs replays the laptop's numbers as a negative case; tests/resourceStreamNames.test.cjs pins the names. Thanks to xet7 !
47 lines
2.3 KiB
JavaScript
47 lines
2.3 KiB
JavaScript
// ============================================================================
|
|
// The event logger of the resource monitors (Admin Panel → Problems → CPU, RAM
|
|
// and Disk usage). Each records ONLY the START and END of a sustained
|
|
// high-usage period - two rows per episode, never a stream - as documents in
|
|
// the existing WeKan database (models/eventLog.js) through a normal Meteor
|
|
// query, so it works the same on FerretDB and MongoDB. Best-effort, never
|
|
// throws. cpuLog.js, ramLog.js and diskLog.js are this with their stream.
|
|
// ============================================================================
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
import EventLog from '/models/eventLog';
|
|
const { sanitizeDetail } = require('/models/lib/securityLogFormat');
|
|
|
|
// A resource monitor reports how busy the machine is, not a vulnerability. Its
|
|
// rows were named like the Hall of Fame entries - RamBleed, CpuBleed, DiskBleed,
|
|
// with CWE-400 - and a laptop with many programs open read as an attack
|
|
// (2026-11-19). They are named for what happened now, carry no CWE, and the
|
|
// rows already stored under the old name are renamed once, at startup.
|
|
export function renameLegacyRows(stream, from, to) {
|
|
if (!from || from === to) return Promise.resolve();
|
|
return EventLog.rawCollection().updateMany({ stream, bleed: from }, { $set: { bleed: to }, $unset: { cwe: '' } })
|
|
.catch(() => {});
|
|
}
|
|
|
|
export function resourceRecorder(defaults) {
|
|
if (Meteor.isServer) Meteor.startup(() => { renameLegacyRows(defaults.stream, defaults.legacyBleed, defaults.bleed); });
|
|
return function record(evt = {}) {
|
|
try {
|
|
const doc = {
|
|
stream: defaults.stream,
|
|
at: evt.at instanceof Date ? evt.at : new Date(),
|
|
severity: evt.severity || 'medium',
|
|
category: evt.category || defaults.category,
|
|
bleed: evt.bleed || defaults.bleed,
|
|
action: evt.action || 'detected',
|
|
source: evt.source || defaults.source,
|
|
...(evt.cwe ? { cwe: evt.cwe } : {}),
|
|
detail: sanitizeDetail(evt.detail),
|
|
};
|
|
const p = EventLog.insertAsync(doc);
|
|
if (p && typeof p.catch === 'function') p.catch(() => {});
|
|
} catch (e) {
|
|
if (process.env.DEBUG === 'true') console.warn(`${defaults.stream} log record failed:`, e && e.message);
|
|
}
|
|
};
|
|
}
|