Coder Social home page Coder Social logo

cwinperfcounter's Introduction

cWinPerfCounter

Access Windows performance counters through Node.js.

Getting Started

  1. Install cWinPerfCounter via NPM.

npm install cwinperfcounter

Optionally: rename cwinperfcounter to cWinPerfCounter: npm is unable to handle the complexity of uppercase characters in a module name. Node.js on Windows does not have this problem, so renaming the folder is not required for you to use the module.

  1. Require cWinPerfCounter in your project.

var cWinPerfCounter=require("cWinPerfCounter");

  1. Instantiate cWinPerfCounter for the performance counter you want to read.

var oPerfCounter = new cWinPerfCounter("\\Processor(_Total)\\% Processor Time");

  1. Read values for the requested performance counter.
setInterval(function() {
  try {
    console.log(oPerfCounter.fnGetValue());
  } catch (oError) {
    console.log(oError);
  }
}, 1000);

This particular performance counter will return the average total CPU usage on your machine since the last time it was read. This means it will not return a value the first time you call it, but only after you have called it twice. The try ... catch will handle the error on the first read.

Notes

cWinPerfCounter cross-platform support

cWinPerfCounter comes with pre-build binaries for all supported processor architectures and Node.js versions (ia32 and x64, Node.js v0.9.0 - v0.12.0). These files are stored in separate sub-folders of the bin folder. The index.js attempts to load each .node file for the user's processor architecture until one works. This means it may attempt to load various versions that fail before it will eventually load the right version and return.

Future Node.js versions may be supported, if they can load the addon for the latest version included in this package. If the requirements for compiled addons change in a future version, an additional build of cWinPerfCounter.node will be required.

Building cWinPerfCounter

The build.cmd script will read a list of combinations of processor architecture and Node.js version from "build-targets.txt". It will build a cWinPerfCounter.node file for each of them and store it in its own sub-folder under the "bin" folder. You can also build a .node file for a single processor architecture and Node.js version by providing them as arguments to build.cmd, eg build.cmd x64 0.10.10.

How to find out what performance counters are available

You can either search the web, or you can run "perfmon.exe" on your machine and follow these steps:

  • open Performance -> Monitoring Tools -> Performance Monitor,
  • right-click on the graph and select "Add Counters...",
  • select and add the counters you are interested in, then click "Ok".
  • right-click the graph again and select "Properties...",
  • in the "Data" tab, you will see a list of the names of the performance counters you have selected. You should be able to use these names with cWinPerfCounter.

License

This code is licensed under CC0 v1.0 Universal.

cwinperfcounter's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

marcominetti

cwinperfcounter's Issues

High CPU usage

Hi there, I'm trying to poll three perfcounter instances every 1000ms... It seems that the fnGetValue is CPU hungry... is that normal (performance counters are CPU hungry) or is there any optimization to be done? any hints?

Can't build for node 5.7.0

I'm really struggling to get anywhere trying to build this for node 5.7.0. It think its something to do with the nan dependency, has anyone has tried it?

I've tried with nan version 1.7

I had to remove the following from package.json to install nan into node_modules since installing it globally causes "Cannot read property 'target' of null" error:

"_requiredBy": [
"#USER"
],

I updated the build-targets.txt by adding the line x64 v5.7.0

I can then npm install [email protected] and the nan folder appears in node_modules.

Building with build x64 5.7.0 then causes a whole bunch of errors which seem like version signature compatibility problems:

cwinperfcounter\node_modules\nan\nan_implementation_12_inl.h(181): error C2660: 'v8::Signature::New' : function does not take 4 arguments [C:\test\cwinperfcounter\build\cWinPerfCounter.vcxproj] cwinperfcounter\node_modules\nan\nan.h(173): error C2995: 'v8::Local<T> _NanEnsureLocal(v8::Local<T>)' : function template has already been defined [C:\test\cwinperfcounter\build\cWinPerfCounter.vcxproj]

Compiling with MSVS 2015

Hi, I've tried yesterday to compile with Visual Studio 2015 and latest node 4.1.1 (its node-gyp should support 2015 build tools).

I've set msvs_version to 2015 and other modules compiles correctly.

npm config set msvs_version 2015

Here I found a couple of exceptions, do you have time to delve into it? Just as forward looking...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.