Files
wekan/server/methods/systemStatus.js
T
Lauri Ojansivu b6a3d98736 Admin Panel / Problems: Memory Usage and Disk usage reports.
The RAM and Disk usage pages were designs that no code carried out. Both
monitors now run beside the CPU one and, like it, record only the start and
the end of a sustained high-usage period:

- Memory: RAM from /proc/meminfo's MemAvailable - os.freemem() is MemFree,
  which counts the page cache as used and shows a healthy server as full -
  and swap, which alone also starts a period. Without /proc/meminfo it uses
  what Node reports. Settings WEKAN_RAM_* and WEKAN_SWAP_HIGH_PERCENT.
- Disk: each filesystem WeKan writes to - the files root, its temp directory
  for uploads and the snap's data directory - measured once per device, with
  an episode of its own. WEKAN_DISK_WATCH_PATHS replaces the paths.
- Each report has a live line above its rows and a URL
  (/admin/problems/ram, /admin/problems/disk). The menu and titles use the
  existing memory-usage and sandstorm-disk-usage keys, which every language
  translates, and the Summary names the cpu, ram and disk streams.

Observe and report only, as designed. The three monitors share one event
recorder (server/lib/resourceLog.js) and one intEnv (models/lib/intEnv.js),
which three files had each defined. The pure halves are tested without
Meteor, and resourceMonitorsWiring checks the wiring and that no copy of
either shared piece returns.

Thanks to xet7 !
2026-10-17 01:14:16 +03:00

80 lines
3.5 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import os from 'os';
import { ReactiveCache } from '/imports/reactiveCache';
import {
getProblemsOverview,
getInProgress,
getLoginProblems,
} from '/server/lib/systemStatus';
import { getCurrentCpu } from '/server/lib/cpuMonitor';
import { getCurrentMemory } from '/server/lib/ramMonitor';
import { getCurrentDisks } from '/server/lib/diskMonitor';
// Admin-gated methods behind the Admin Panel / Problems "Status" overview. The
// same data is available without the Admin Panel via `snap run wekan.problems`.
async function requireAdmin() {
const user = await ReactiveCache.getCurrentUser();
if (!user || !user.isAdmin) {
throw new Meteor.Error('not-authorized', 'Admin only');
}
return user;
}
// Problem-specific detail, mirroring the `snap run wekan.problems <area>`
// sub-commands. Kept in one place so the Admin Panel and the snap command agree.
function cpuDetail() {
const cpus = os.cpus() || [];
const mem = process.memoryUsage();
return {
area: 'cpu',
title: 'CPU usage',
// The live figure shown above the search box on the CPU usage page. Same
// sample the CPU monitor writes its event rows from, so the header and the
// rows below it never disagree.
current: getCurrentCpu(),
loadAverage: os.loadavg(), // 1 / 5 / 15 min
cpuCount: cpus.length,
cpuModel: cpus.length ? cpus[0].model : '',
uptimeSeconds: Math.round(process.uptime()),
rssBytes: mem.rss,
heapUsedBytes: mem.heapUsed,
note: 'Load average is machine-wide (1/5/15 min). rss/heap are the WeKan server process. Sustained load near or above the CPU count means the machine is saturated. If `top` shows the ferretdb process pegged near 100%/200% for a long time, the FerretDB v1 (SQLite) backend is saturated under WeKan\'s poll load (symptoms: pages take minutes, counts stuck at 0, raw i18n keys). Mitigation: run on MongoDB (snap: `snap set wekan database=mongodb`) or migrate text data across, and check for a migration/repair still running.',
};
}
Meteor.methods({
// The full Problems "Status" overview: everything in progress + problems found.
async systemStatusReport() {
await requireAdmin();
const [overview, loginProblems] = await Promise.all([
getProblemsOverview(),
getLoginProblems(),
]);
return { overview, loginProblems };
},
// Just the in-progress migrations/repairs (cheap; polled by the Status page).
async migrationsInProgress() {
await requireAdmin();
return getInProgress();
},
// Detail for one problem area ('cpu', 'ram', 'disk'); mirrors the snap sub-command.
// `area` MUST be check()ed: Meteor runs with audit-argument-checks, so a method
// that receives an argument it never checks throws "Did not check() all arguments"
// on every call. Nothing passed an argument here until the CPU usage page started
// polling problemDetailReport('cpu'), which then failed every 5 seconds.
async problemDetailReport(area) {
check(area, Match.OneOf(String, null, undefined));
await requireAdmin();
if (area === 'cpu') return cpuDetail();
if (area === 'ram') return { area: 'ram', current: getCurrentMemory() };
if (area === 'disk') return { area: 'disk', current: getCurrentDisks() };
if (area === 'login') return { area: 'login', checks: await getLoginProblems() };
if (area === 'status' || !area) return getProblemsOverview();
throw new Meteor.Error('unknown-area', `Unknown problem area: ${area}`);
},
});