當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript humanize.filesize函數代碼示例

本文整理匯總了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)
        );
    }
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:11,代碼來源:test_address_space_dispose.ts

示例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;
                }
            }
        }
    });
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:34,代碼來源:vendor_diagnostic_nodes.ts

示例3:

 handler: () => ({
   hostname: os.hostname(),
   arch: os.arch(),
   platfoirm: os.platform(),
   cpus: os.cpus().length,
   totalmem: humanize.filesize(os.totalmem()),
   networkInterfaces: os.networkInterfaces()
 })
開發者ID:pdxmholmes,項目名稱:alpine-node-hello,代碼行數:8,代碼來源:index.ts

示例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); }
 });
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:5,代碼來源:vendor_diagnostic_nodes.ts

示例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,
//.........這裏部分代碼省略.........
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:101,代碼來源:vendor_diagnostic_nodes.ts


注:本文中的humanize.filesize函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。