本文整理汇总了TypeScript中os.totalmem函数的典型用法代码示例。如果您正苦于以下问题:TypeScript totalmem函数的具体用法?TypeScript totalmem怎么用?TypeScript totalmem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了totalmem函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getProcessItem
function getProcessItem(processes: any[], item: ProcessItem, indent: number): void {
const isRoot = (indent === 0);
const MB = 1024 * 1024;
let name = item.name;
if (isRoot) {
name = `${product.applicationName} main`;
}
if (name === 'window') {
const windowTitle = mapPidToWindowTitle.get(item.pid);
name = windowTitle !== undefined ? `${name} (${mapPidToWindowTitle.get(item.pid)})` : name;
}
// Format name with indent
const formattedName = isRoot ? name : `${repeat(' ', indent)} ${name}`;
const memory = process.platform === 'win32' ? item.mem : (totalmem() * (item.mem / 100));
processes.push({
cpu: Number(item.load.toFixed(0)),
memory: Number((memory / MB).toFixed(0)),
pid: Number((item.pid).toFixed(0)),
name,
formattedName,
cmd: item.cmd
});
// Recurse into children if any
if (Array.isArray(item.children)) {
item.children.forEach(child => getProcessItem(processes, child, indent + 1));
}
}
示例2: getProcessItem
function getProcessItem(mapPidToWindowTitle: Map<number, string>, processes: ProcessInfo[], item: ProcessItem, indent: number): void {
const isRoot = (indent === 0);
const MB = 1024 * 1024;
// Format name with indent
let name: string;
if (isRoot) {
name = `${product.applicationName} main`;
} else {
name = `${repeat('--', indent)} ${item.name}`;
if (item.name === 'window') {
name = `${name} (${mapPidToWindowTitle.get(item.pid)})`;
}
}
const memory = process.platform === 'win32' ? item.mem : (os.totalmem() * (item.mem / 100));
processes.push({
cpu: Number(item.load.toFixed(0)),
memory: Number((memory / MB).toFixed(0)),
pid: Number((item.pid).toFixed(0)),
name
});
// Recurse into children if any
if (Array.isArray(item.children)) {
item.children.forEach(child => getProcessItem(mapPidToWindowTitle, processes, child, indent + 1));
}
}
示例3: computeStartupMetrics
public computeStartupMetrics(): void {
const now = Date.now();
const initialStartup = !!this.isInitialStartup;
const start = initialStartup ? this.start : this.windowLoad;
let totalmem: number;
let freemem: number;
let cpus: { count: number; speed: number; model: string; };
let platform: string;
let release: string;
let loadavg: number[];
let meminfo: IMemoryInfo;
try {
totalmem = os.totalmem();
freemem = os.freemem();
platform = os.platform();
release = os.release();
loadavg = os.loadavg();
meminfo = process.getProcessMemoryInfo();
const rawCpus = os.cpus();
if (rawCpus && rawCpus.length > 0) {
cpus = { count: rawCpus.length, speed: rawCpus[0].speed, model: rawCpus[0].model };
}
} catch (error) {
console.error(error); // be on the safe side with these hardware method calls
}
this._startupMetrics = {
version: 1,
ellapsed: Math.round(this.workbenchStarted.getTime() - start.getTime()),
timers: {
ellapsedExtensions: Math.round(this.afterExtensionLoad.getTime() - this.beforeExtensionLoad.getTime()),
ellapsedExtensionsReady: Math.round(this.afterExtensionLoad.getTime() - start.getTime()),
ellapsedRequire: Math.round(this.afterLoadWorkbenchMain.getTime() - this.beforeLoadWorkbenchMain.getTime()),
ellapsedViewletRestore: Math.round(this.restoreViewletDuration),
ellapsedEditorRestore: Math.round(this.restoreEditorsDuration),
ellapsedWorkbench: Math.round(this.workbenchStarted.getTime() - this.beforeWorkbenchOpen.getTime()),
ellapsedWindowLoadToRequire: Math.round(this.beforeLoadWorkbenchMain.getTime() - this.windowLoad.getTime()),
ellapsedTimersToTimersComputed: Date.now() - now
},
platform,
release,
totalmem,
freemem,
meminfo,
cpus,
loadavg,
initialStartup,
hasAccessibilitySupport: !!this.hasAccessibilitySupport,
emptyWorkbench: this.isEmptyWorkbench
};
if (initialStartup) {
this._startupMetrics.timers.ellapsedAppReady = Math.round(this.appReady.getTime() - this.start.getTime());
this._startupMetrics.timers.ellapsedWindowLoad = Math.round(this.windowLoad.getTime() - this.appReady.getTime());
}
}
示例4:
handler: () => ({
hostname: os.hostname(),
arch: os.arch(),
platfoirm: os.platform(),
cpus: os.cpus().length,
totalmem: humanize.filesize(os.totalmem()),
networkInterfaces: os.networkInterfaces()
})
示例5: init
/**
* Init app
*/
async function init(): Promise<State> {
console.log('Welcome to Misskey!\n');
console.log(chalk.bold('Misskey Core <aoi>'));
let warn = false;
// Get commit info
const commit = await prominence(git).getLastCommit();
console.log(`commit: ${commit.shortHash} ${commit.author.name} <${commit.author.email}>`);
console.log(` ${new Date(parseInt(commit.committedOn, 10) * 1000)}`);
console.log('\nInitializing...\n');
if (IS_DEBUG) {
logWarn('It is not in the Production mode. Do not use in the Production environment.');
}
logInfo(`environment: ${env}`);
// Get machine info
const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1);
const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1);
logInfo(`MACHINE: ${os.hostname()}`);
logInfo(`MACHINE: CPU: ${os.cpus().length}core`);
logInfo(`MACHINE: MEM: ${totalmem}GB (available: ${freemem}GB)`);
if (!fs.existsSync(require('./config').configPath)) {
logFailed('Configuration not found');
return State.failed;
}
// Load config
const conf = require('./config').default;
logDone('Success to load configuration');
logInfo(`maintainer: ${conf.maintainer}`);
checkDependencies();
// Check if a port is being used
if (await portUsed.check(conf.port)) {
logFailed(`Port: ${conf.port} is already used!`);
return State.failed;
}
// Try to connect to MongoDB
try {
await initdb(conf);
logDone('Success to connect to MongoDB');
} catch (e) {
logFailed(`MongoDB: ${e}`);
return State.failed;
}
return warn ? State.warn : State.success;
}
示例6: show
public static show(): void {
const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1);
const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1);
const logger = new Logger('Machine');
logger.info(`Hostname: ${os.hostname()}`);
logger.info(`Platform: ${process.platform}`);
logger.info(`Architecture: ${process.arch}`);
logger.info(`CPU: ${os.cpus().length} core`);
logger.info(`MEM: ${totalmem}GB (available: ${freemem}GB)`);
}
示例7: logging
export function logging(args) {
const pid = process.pid;
const processMem = process.memoryUsage();
const rss = processMem.rss;
const heapTotal = processMem.heapTotal;
const heapUsed = processMem.heapUsed;
const osFreeMem = os.freemem();
const osTotalMem = os.totalmem();
const la = os.loadavg();
return `${pid},${args.time},${rss},${heapUsed},${heapTotal},${osFreeMem},${osTotalMem},${la[0]},${la[1]},${la[2]}\n`;
}
示例8: Date
,(msg: rcf.IMessage): void => {
console.log(new Date().toISOString() + ': msg-rcvd: ' + JSON.stringify(msg));
let gMsg: GridMessage = msg.body;
if (gMsg.type === 'launch-task') {
let task: ITask = gMsg.content;
let TrackingId = tasksTracker.beginTracking(task);
let taskExec = getTaskExec(nodeId, gridDB);
taskExec.on("error", (err: any) => {
console.error(new Date().toISOString() + ": !!! Error running task " + JSON.stringify(task) + ": " + JSON.stringify(err) + " :-(");
// TODO: sent error message to the server
}).on("exec-params", (taskExecParams: ITaskExecParams) => {
tasksTracker.updateTracking(TrackingId, {cmd: taskExecParams.cmd, envJSON: taskExecParams.envJSON});
console.log(new Date().toISOString() + ": running task " + JSON.stringify(task) + " with exec-params=\n" + JSON.stringify(taskExecParams, null, 2));
}).on("started", (pid: number) => {
tasksTracker.updateTracking(TrackingId, {pid});
console.log(new Date().toISOString() + ": task " + JSON.stringify(task) + " started with pid=" + pid);
}).on("finished", (retCode: number) => {
console.log(new Date().toISOString() + ": task " + JSON.stringify(task) + " finished with retCode=" + retCode);
}).run(task)
.then(() => {
tasksTracker.endTracking(TrackingId);
notifyDispatcherTaskComplete(task)
.then(() => {
console.log(new Date().toISOString() + ': <task-complete> notification for task ' + JSON.stringify(task) + ' successfully sent to the dispatcher :-)');
}).catch((err: any) => {
console.error(new Date().toISOString() + ': !!! Error sending <task-complete> notification for task '+ JSON.stringify(task) + ' to the dispatcher :-(');
});
});
} else if (gMsg.type === 'kill-processes-tree') {
let pids: number[] = gMsg.content;
killProcessesTree(pids);
} else if (gMsg.type === 'node-query-status') {
let request: NodeQueryStatusRequest = gMsg.content;
let response: NodeQueryStatusResponse = {
QueryId: request.QueryId
,Status: {
FreeMem: os.freemem()
,TotalMem: os.totalmem()
,UptimeSec: os.uptime()
,RunningTasks: tasksTracker.toJSON()
}
};
sendNodeQueryStatusResponse(response)
.then(() => {
}).catch((err: any) => {
console.error(new Date().toISOString() + ': !!! Error sending back <node-query-status> message: ' + JSON.stringify(err));
});
}
},{})
示例9: getMachineInfo
export function getMachineInfo(): IMachineInfo {
const MB = 1024 * 1024;
const GB = 1024 * MB;
const machineInfo: IMachineInfo = {
os: `${os.type()} ${os.arch()} ${os.release()}`,
memory: `${(os.totalmem() / GB).toFixed(2)}GB (${(os.freemem() / GB).toFixed(2)}GB free)`,
vmHint: `${Math.round((virtualMachineHint.value() * 100))}%`,
};
const cpus = os.cpus();
if (cpus && cpus.length > 0) {
machineInfo.cpus = `${cpus[0].model} (${cpus.length} x ${cpus[0].speed})`;
}
return machineInfo;
}
示例10:
osUtils.cpuUsage(cpuUsage => {
const disk = diskusage.checkSync(os.platform() == 'win32' ? 'c:' : '/');
event.stream.emit('status', {
node: {
release: (process as any).release.name,
lts: (process as any).release.lts,
version: process.version
},
machine: os.hostname(),
pid: process.pid,
uptime: process.uptime(),
cpuUsage: cpuUsage,
mem: {
total: os.totalmem(),
free: os.freemem()
},
disk
});
});