You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
最好显示前 3 名,没有必要显示更多。
From a usability perspective, I would like to customize the selection of process monitoring, such as when my server is running "Home Assistant," I can know when its process is killed, so that I can immediately maintain it.
and,Developing JavaTypeScript has been challenging for me, and I apologize that I am unable to fix the issue and submit a PR. However, I can provide you with a possible solution and reference code.
I hope to add process monitoring for the system.
I want to add a process monitor in the server monitor, next to docker
I hope that's how he works
processMonitor.ts
######################################
import { exec } from 'child_process';
export interface ProcessInfo {
pid: number;
name: string;
cpu: number;
memory: number;
}
const systemUsers = ['root', 'system', 'daemon'];
export const getProcessesInfo = async (): Promise<ProcessInfo[]> => {
return new Promise((resolve, reject) => {
exec('ps aux --sort=-%cpu,-rss', (error, stdout, stderr) => {
if (error) {
reject(
exec error: ${error}
);return;
}
});
};
##########################
serverStatus.ts
##########################
import { Router, Request, Response } from 'express';
import { body, header, param } from 'express-validator';
import { validate } from '../middleware/validate.js';
import { recordServerStatus } from '../model/serverStatus.js';
import fs from 'fs-extra';
import { libraryPath } from '../utils/lib.js';
import { getProcessesInfo, ProcessInfo } from '../utils/processMonitor.js';
export const serverStatusRouter = Router();
const installScript = fs.readFileSync(libraryPath.installScript);
// 服务器状态报告路由
serverStatusRouter.post(
'/report',
validate(
header('x-tianji-report-version').isSemVer(),
body('workspaceId').isString(),
body('name').isString(),
body('hostname').isString(),
body('timeout').optional().isInt(),
body('payload').isObject()
),
async (req: Request, res: Response) => {
const body = req.body;
recordServerStatus(body);
res.send('success');
}
);
// 安装脚本路由
serverStatusRouter.get(
'/:workspaceId/install.sh',
validate(param('workspaceId').isString()),
async (req: Request, res: Response) => {
const { workspaceId } = req.params;
const queryUrl = req.query.url ? String(req.query.url) : undefined;
const server = queryUrl ||
${req.protocol}://${req.get('Host')}
;res
.setHeader('Content-Type', 'text/plain')
.send(
String(installScript)
.replace('{{DEFAULT_SERVER}}', server)
.replace('{{DEFAULT_WORKSPACE}}', workspaceId)
);
}
);
// 进程监控路由
serverStatusRouter.get(
'/process-monitor',
async (req: Request, res: Response) => {
try {
const processes: ProcessInfo[] = await getProcessesInfo();
res.json(processes);
} catch (err) {
res.status(500).json({ error: '获取进程信息失败' });
}
}
);
#############################
The text was updated successfully, but these errors were encountered: