本文整理汇总了TypeScript中humanize.filesize函数的典型用法代码示例。如果您正苦于以下问题:TypeScript filesize函数的具体用法?TypeScript filesize怎么用?TypeScript filesize使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filesize函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: dumpMemoryUse
function dumpMemoryUse() {
if (process.memoryUsage) {
const m = process.memoryUsage();
const h = require("humanize");
console.log(" memoryUsage = ",
" rss =", h.filesize(m.rss),
" heapTotal =", h.filesize(m.heapTotal),
" heapUsed =", h.filesize(m.heapUsed)
);
}
}
示例2: addVariableWithHumanizeText
/**
* @method addVariableWithHumanizeText
* @param namespace
* @param options
* @param options.browseName
* @private
*/
function addVariableWithHumanizeText(namespace: Namespace, options: any) {
assert(options.componentOf || options.organizedBy);
assert(typeof options.description === "string");
const variable = namespace.addVariable(options);
// add the xxxAsText property
namespace.addVariable({
propertyOf: variable,
browseName: options.browseName.name.toString() + "AsText",
dataType: "String",
description: options.description + " as text",
minimumSamplingInterval: options.minimumSamplingInterval,
value: {
get() {
const v = options.value.get();
if (v instanceof Variant) {
return new Variant({dataType: DataType.String, value: humanize.filesize(v.value)});
} else {
return v;
}
}
}
});
}
示例3:
handler: () => ({
hostname: os.hostname(),
arch: os.arch(),
platfoirm: os.platform(),
cpus: os.cpus().length,
totalmem: humanize.filesize(os.totalmem()),
networkInterfaces: os.networkInterfaces()
})
示例4:
usage.lookup(pid, options, (err: Error| null, result: any) => {
usage_result = result;
console.log("result Used Memory: ", humanize.filesize(result.memory), " CPU ", Math.round(result.cpu), " %");
if (err) { console.log("err ", err); }
});
示例5: install_optional_cpu_and_memory_usage_node
export function install_optional_cpu_and_memory_usage_node(server: any) {
const engine = server.engine;
assert(engine instanceof ServerEngine);
let usage: any;
try {
usage = require("usage");
} catch (err) {
console.log("err", err.message);
usage = null;
// xx return;
}
const addressSpace = engine.addressSpace;
const namespace = addressSpace.getOwnNamespace();
const folder = addressSpace.findNode(ObjectIds.Server_VendorServerInfo);
let usage_result = {memory: 0, cpu: 100};
const pid = process.pid;
if (usage) {
const options = {keepHistory: true};
setInterval(() => {
usage.lookup(pid, options, (err: Error| null, result: any) => {
usage_result = result;
console.log("result Used Memory: ", humanize.filesize(result.memory), " CPU ", Math.round(result.cpu), " %");
if (err) { console.log("err ", err); }
});
}, 1000);
namespace.addVariable({
organizedBy: folder,
browseName: "CPUUsage",
dataType: "Double",
description: "Current CPU usage of the server process",
minimumSamplingInterval: 1000,
nodeId: "s=CPUUsage",
value: {
get: () => {
if (!usage_result) {
return StatusCodes.BadResourceUnavailable;
}
return new Variant({dataType: DataType.Double, value: Math.round(usage_result.cpu)});
}
}
});
addVariableWithHumanizeText(namespace, {
browseName: "MemoryUsage",
dataType: "Number",
description: "Current memory usage of the server process",
minimumSamplingInterval: 1000,
nodeId: "s=MemoryUsage",
organizedBy: folder,
value: {
get: () => {
if (!usage_result) {
return StatusCodes.BadResourceUnavailable;
}
return new Variant({dataType: DataType.UInt32, value: usage_result.memory});
}
}
});
} else {
console.log("skipping installation of cpu_usage and memory_usage nodes");
}
namespace.addVariable({
organizedBy: folder,
browseName: "PercentageMemoryUsed",
dataType: "Number",
description: "% of memory used by the server",
minimumSamplingInterval: 1000,
nodeId: "s=PercentageMemoryUsed",
value: {
get() {
const percent_used = Math.round((os.totalmem() - os.freemem()) / os.totalmem() * 100);
return new Variant({dataType: DataType.Double, value: percent_used});
}
}
});
addVariableWithHumanizeText(namespace, {
organizedBy: folder,
accessLevel: "CurrentRead",
browseName: "SystemMemoryTotal",
dataType: "Number",
description: "Total Memory usage of the server",
minimumSamplingInterval: 1000,
//.........这里部分代码省略.........