{"id":15652901,"url":"https://github.com/kyleross/windows-cpu","last_synced_at":"2025-04-30T17:04:15.578Z","repository":{"id":12565217,"uuid":"15235656","full_name":"KyleRoss/windows-cpu","owner":"KyleRoss","description":"CPU monitoring utilities for Node.js apps on Windows.","archived":false,"fork":false,"pushed_at":"2018-07-05T19:03:34.000Z","size":49,"stargazers_count":30,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-30T17:04:09.070Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KyleRoss.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-16T19:57:33.000Z","updated_at":"2023-12-29T14:38:07.000Z","dependencies_parsed_at":"2022-09-26T18:40:41.723Z","dependency_job_id":null,"html_url":"https://github.com/KyleRoss/windows-cpu","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleRoss%2Fwindows-cpu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleRoss%2Fwindows-cpu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleRoss%2Fwindows-cpu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleRoss%2Fwindows-cpu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KyleRoss","download_url":"https://codeload.github.com/KyleRoss/windows-cpu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251748938,"owners_count":21637416,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:44:12.607Z","updated_at":"2025-04-30T17:04:15.019Z","avatar_url":"https://github.com/KyleRoss.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# windows-cpu\n\n[![NPM Downloads](https://img.shields.io/npm/v/windows-cpu.svg?style=for-the-badge)](https://www.npmjs.com/package/windows-cpu) [![NPM Downloads](https://img.shields.io/npm/dt/windows-cpu.svg?style=for-the-badge)](https://www.npmjs.com/package/windows-cpu) [![GitHub stars](https://img.shields.io/github/stars/KyleRoss/windows-cpu.svg?style=for-the-badge)](https://github.com/KyleRoss/windows-cpu/stargazers) [![GitHub issues](https://img.shields.io/github/issues/KyleRoss/windows-cpu.svg?style=for-the-badge)](https://github.com/KyleRoss/windows-cpu/issues) [![GitHub license](https://img.shields.io/github/license/KyleRoss/windows-cpu.svg?style=for-the-badge)](https://github.com/KyleRoss/windows-cpu/blob/master/LICENSE) [![AppVeyor tests](https://img.shields.io/appveyor/tests/KyleRoss/windows-cpu/master.svg?style=for-the-badge)](https://ci.appveyor.com/project/KyleRoss/windows-cpu/branch/master)\n\n\nCPU monitoring utilities for Node.js apps on Windows.\n\n##### NOTE: Version 1.0.0+ only supports Node v8+. If you need to support an older version of Node, install `windows-cpu@0.1.6` - See [version 0.1.6](https://github.com/KyleRoss/windows-cpu/tree/legacy).\n\n## About\nA small API that provides load information about any process or the system on Windows platforms. Node.js does have `os.loadavg()` although it does not work correctly in Windows. Windows-CPU is a module that uses native Windows commands to compile load information. It's a lightweight module that has only one dependency and suitable tests.\n\n**Supported Platforms**\n\n| Windows Version     | Supported? | Notes                                                     |\n|---------------------|------------|-----------------------------------------------------------|\n| XP Home             | No         | Does not have `wmic`. Thanks @inexist3nce                 |\n| XP Professional     | Yes        | Thanks @inexist3nce                                       |\n| Windows 7           | Yes        |                                                           |\n| Windows Server 2008 | Yes        |                                                           |\n| Windows 8           | Yes        | Thanks @SkyLined, @EricMcRay, @scriptnull, @UltimateBrent |\n| Windows 10          | Yes        | Thanks @inexist3nce                                       |\n\n## Important Notes\nThis module has only been tested on a Windows 7 and 2008 Server machine. I do not have access to any other versions of Windows to test, so anyone willing to test this script on other versions and create a pull request for README.md with supported platforms, would be very helpful.\n\nThis module uses child processes to call WMIC to gather it's information, if you do not have this command available or cannot spawn child processes, this module will not be of much help to you.\n\n## Getting Started\nInstall windows-cpu via NPM.\n\n```bash\nnpm install windows-cpu --save\n```\n\nRequire windows-cpu in your own Node.js application.\n\n```js\nconst cpu = require('windows-cpu');\n```\n\n----------\n\n# API Documentation\nWhen requiring `windows-cpu`, you are returned an isntance of the `WindowsCPU` class. To get access to the constructor to create your own instance, you may do:\n\n```js\nconst WindowsCPU = require('windows-cpu').WindowsCPU;\nconst cpu = new WindowsCPU();\n// ...\n```\n\n## Properties\n#### wmic _{String}_\nPath to `wmic` executable. Allows overriding the path to the executable for all `wmic` commands. Default: `${process.env.SystemRoot}\\System32\\wbem\\wmic.exe`\n\n**Example:**\n```js\nconst cpu = require('windows-cpu');\nconst path = require('path');\n\ncpu.wmic = path.join('/Windows', 'path', 'to', 'wmic.exe');\n// =\u003e C:\\Windows\\path\\to\\wmic.exe\n```\n\n## Methods\n\n#### isSupported()\nChecks if the current system supports WindowsCPU. It checks to ensure the platform is `win32` and that WMIC exists on the system.\n\n**Example:**\n```js\nif(!cpu.isSupported()) {\n    throw new Error('windows-cpu is not supported on this platform');\n}\n```\n\n###### Returns: _Boolean_\n\u003e `true` if system is supported, otherwise `false`.\n\n#### totalLoad()\nGets the total CPU load of the system for each physical CPU.\n\n**Example:**\n```js\n// Promise\ncpu.totalLoad().then(load =\u003e {\n    console.log(load);\n    // Single CPU example:\n    // =\u003e [10]\n    // Multi-CPU example:\n    // =\u003e [10, 5]\n});\n\n// async/await\nlet load = await cpu.totalLoad();\nconsole.log(load);\n// =\u003e [10]\n```\n\n###### Returns: _Promise[Array]_\n\u003e Resolves with an array of load percentages for each core of the processor.\n\n#### findLoad([process])\nGets the load of all processes running on the machine or the load of a specific process if `process` is provided. The parameter `process` may be a string (process name) or number (process ID) to get the load for.\n\n**Example:**\n```js\n// Without process parameter\ncpu.findLoad().then(({ load, found }) =\u003e {\n    console.log(load);\n    // =\u003e [40]\n    console.log(found);\n    /* =\u003e\n        [{\n            pid: 12345,\n            process: 'Chrome',\n            load: 1\n        }, ...]\n    */\n});\n\n// With process parameter\ncpu.findLoad('Chrome').then(({ load, found }) =\u003e {\n    console.log(load);\n    // =\u003e [1]\n    console.log(found);\n    /* =\u003e\n        [{\n            pid: 12345,\n            process: 'Chrome',\n            load: 1\n        }]\n    */\n});\n\n// async/await\nlet { load, found } = await cpu.findLoad('Chrome');\nconsole.log(load);\nconsole.log(found);\n```\n\n###### Returns: _Promise[Object]_\n\u003e Resolves with an object containing `load` (Numeric total percent the process(es) load) and `found` (array of objects containing `pid` - process id, `process` - process name, `load` - the load percent of this process).\n\n#### nodeLoad()\nShortcut for calling `cpu.findLoad('node')`. This will return the current load for all `node` processes running on the system.\n\n**Example:**\n```js\n// Promise\ncpu.nodeLoad().then(({ load, found }) =\u003e {\n    console.log(load);\n    // =\u003e [0]\n    console.log(found);\n    /* =\u003e\n        [{\n            pid: 12345,\n            process: 'node',\n            load: 0\n        }]\n    */\n});\n\n// async/await\nlet { load, found } = await cpu.nodeLoad();\nconsole.log(load);\nconsole.log(found);\n```\n\n###### Returns: _Promise[Object]_\n\u003e Resolves with the same information as `findLoad()`.\n\n#### thisLoad()\nShortcut for calling `cpu.findLoad(process.pid)`. This will return the load for the current node process running.\n\n**Example:**\n```js\n// Promise\ncpu.thisLoad().then(({ load, found }) =\u003e {\n    console.log(load);\n    // =\u003e [0]\n    console.log(found);\n    /* =\u003e\n        [{\n            pid: 12345,\n            process: 'node',\n            load: 0\n        }]\n    */\n});\n\n// async/await\nlet { load, found } = await cpu.thisLoad();\nconsole.log(load);\nconsole.log(found);\n```\n\n###### Returns: _Promise[Object]_\n\u003e Resolves with the same information as `findLoad()`.\n\n#### cpuInfo()\nGets a list of all CPUs installed in the machine.\n\n**Example:**\n```js\n// Promise\ncpu.cpuInfo().then(cpus =\u003e {\n    console.log(cpus);\n    /* =\u003e\n        [\n            'Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz',\n            'Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz'\n        ]\n    */\n});\n\n// async/await\nlet cpus = await cpu.cpuInfo();\nconsole.log(cpus);\n```\n\n###### Returns: _Promise[Array]_\n\u003e Resolves with array of CPU(s).\n\n#### totalMemoryUsage()\nGets the total memory usage for the system in multiple formats.\n\n**Example:**\n```js\n// Promise\ncpu.totalMemoryUsage().then(mem =\u003e {\n    console.log(mem);\n    /* =\u003e\n        {\n            usageInKb: 3236244,\n            usageInMb: 3160.39453125,\n            usageInGb: 3.086322784423828 \n        }\n    */\n});\n\n// async/await\nlet mem = cpu.totalMemoryUsage();\nconsole.log(mem);\n```\n\n###### Returns: _Promise[Object]_\n\u003e Resolves with object containing keys: `usageInKb` (total in KB), `usageInMb` (total in MB), and `usageInGb` (total in GB).\n\n----------\n\n## Issues\nPlease post any issues you find in the issues section of this repository.\n\n## Contributing\nIf you would like to contribute to windows-cpu, please make sure you follow the guidelines in CONTRIBUTING.md in this repository.\n\n## License\nLicensed under the MIT License. Please see LICENSE in this repository for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyleross%2Fwindows-cpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyleross%2Fwindows-cpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyleross%2Fwindows-cpu/lists"}