Permalink
Browse files

Merge pull request #8 from duralog/master

updated to compile on latest node version
  • Loading branch information...
2 parents 1ad5a4e + 07e6ae4 commit 3affdbe7d9c2e638b3f0834e3a910936b37e050a Worms David committed Mar 23, 2013
Showing with 1,918 additions and 1,278 deletions.
  1. +23 −0 binding.gyp
  2. +1 −1 deps/sigar
  3. +6 −1 package.json
  4. +106 −0 readme.md
  5. +47 −0 samples/cpu_usage.ls
  6. +1,167 −1,275 src/node_sigar.cc
  7. +74 −0 src/node_sigar.h
  8. +1 −1 src/node_sigar_format.cc
  9. +493 −0 src/v8u.hpp
View
@@ -0,0 +1,23 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'sigar',
+ 'sources': [ 'src/node_sigar.cc' ],
+ 'cflags!': [ '-fno-exceptions' ],
+ 'cflags_cc!': [ '-fno-exceptions' ],
+ "libraries": [
+ "<(module_root_dir)/build/sigar/src/.libs/libsigar.a"
+ ],
+ "include_dirs": [
+ 'deps/sigar/include'
+ ],
+ 'conditions': [
+ ['OS=="mac"', {
+ 'xcode_settings': {
+ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
+ }
+ }]
+ ]
+ }
+ ]
+}
View
@@ -16,15 +16,20 @@
"dependencies": {},
"devDependencies": {
"coffee-script": "latest",
+ "printf": "latest",
"mocha": "latest",
"should": "latest"
},
- "contributors": [
+ "contributors": [
+ { "name": "Kenneth Bentley", "email": "funisher@gmail.com" },
{ "name": "David Worms", "email": "david@adaltas.com" }
],
"main": "index",
+ "gypfile": true,
"engines": { "node": ">= 0.6.0" },
"scripts": {
+ "cmakenotworking": "mkdir -p build/sigar && cp -rp deps/sigar/* build/sigar/ && cd build/sigar && cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=false . && cmake --build . && node-gyp configure && node-gyp build",
+ "preinstall": "mkdir -p build/sigar && cp -rp deps/sigar/* build/sigar/ && cd build/sigar && ./autogen.sh && ./configure --prefix=`pwd`/build/sigar --with-pic && make && make install && cd ../.. && node-gyp configure && node-gyp build",
"test": "mocha"
}
}
View
@@ -18,3 +18,109 @@ SIGAR is a cross platform interface for gathering system information. From the p
* TCP and UDP connection tables
* Network route table
+```
+var sigar = require('sigar');
+console.log(sigar.version()); // returns the version
+
+// invoke the library
+var Sigar = sigar.init();
+console.log(sigar.cpu()); // {}
+
+```
+
+API
+===
+
+Sigar.mem();
+```
+> {
+ ram: Number
+ total: Number
+ used: Number
+ free: Number
+ actual_used: Number
+ actual_free: Number
+ used_percent: Number
+ free_percent: Number
+}
+```
+Sigar.swap();
+```
+{
+ total: Number
+ used: Number
+ free: Number
+ page_in: Number
+ page_out: Number
+}
+```
+Sigar.uptime();
+```
+> 52883 // seconds
+```
+Sigar.loadavg();
+```
+[0.11, 0.13, 0.09]
+```
+Sigar.resourceLimit();
+Sigar.whoList();
+Sigar.sysInfo();
+Sigar.fqdn();
+// CPU
+Sigar.cpu();
+Sigar.cpuList();
+Sigar.cpuInfoList();
+// Process
+Sigar.procList();
+Sigar.procStat();
+Sigar.procMem();
+Sigar.procCred();
+Sigar.procTime();
+Sigar.procCpu();
+Sigar.procState();
+Sigar.procArgs();
+Sigar.procEnv();
+Sigar.procFd();
+Sigar.procExe();
+Sigar.procModules();
+Sigar.procPort();
+Sigar.threadCpu();
+// Disk
+Sigar.fileSystemList();
+Sigar.fileSystemUsage();
+Sigar.fileSystemPing();
+// Network
+Sigar.netInfo();
+Sigar.netRouteList();
+Sigar.netInterfaceList();
+Sigar.netInterfaceConfig();
+Sigar.netInterfaceConfigPrimary();
+Sigar.netInterfaceStat();
+Sigar.netConnectionList();
+Sigar.netListenAddress();
+Sigar.netStat();
+Sigar.netStatPort();
+Sigar.tcp();
+Sigar.nfsClientV2();
+Sigar.nfsServerV2();
+Sigar.arpList();
+// Misc
+Sigar.rpcPing();
+
+
+
+TODO
+====
+
+ * compile the entire library with gyp
+ * fix up the tests (and improve on them)
+ * utilize / reimplement / remove `sigar_format.c` functions
+ * convert functions without args to be getters
+ * provide async funcs for long-running actions
+ * old / broken code still exists for converting network addresses (see `node_sigar_utils.cc::node_sigar_str2net_address()`)
+
+
+LICENSE
+=======
+
+Node Sigar is licensed under the BSD license.
View
@@ -0,0 +1,47 @@
+
+Sigar = require '../build/Release/sigar' .init!
+printf = require 'printf'
+
+# replication of `sigar_cpu_perc_calculate`
+# please refer to `sigar_format.c` for more info
+
+prev = Sigar.cpu!
+setInterval ->
+ curr = Sigar.cpu!
+ diff_user = curr.user - prev.user
+ diff_sys = curr.sys - prev.sys
+ diff_nice = curr.nice - prev.nice
+ diff_idle = curr.idle - prev.idle
+ diff_wait = curr.wait - prev.wait
+ diff_irq = curr.irq - prev.irq
+ diff_soft_irq = curr.soft_irq - prev.soft_irq
+ diff_stolen = curr.stolen - prev.stolen
+
+ diff_user = if diff_user < 0 then 0 else diff_user
+ diff_sys = if diff_sys < 0 then 0 else diff_sys
+ diff_nice = if diff_nice < 0 then 0 else diff_nice
+ diff_idle = if diff_idle < 0 then 0 else diff_idle
+ diff_wait = if diff_wait < 0 then 0 else diff_wait
+ diff_irq = if diff_irq < 0 then 0 else diff_irq
+ diff_soft_irq = if diff_soft_irq < 0 then 0 else diff_soft_irq
+ diff_stolen = if diff_stolen < 0 then 0 else diff_stolen
+
+ diff_total =
+ diff_user + diff_sys + diff_nice + diff_idle +
+ diff_wait + diff_irq + diff_soft_irq +
+ diff_stolen
+
+ perc = {
+ user: diff_user / diff_total
+ sys: diff_sys / diff_total
+ nice: diff_nice / diff_total
+ idle: diff_idle / diff_total
+ wait: diff_wait / diff_total
+ irq: diff_irq / diff_total
+ soft_irq: diff_soft_irq / diff_total
+ stolen: diff_stolen / diff_total
+ }
+ perc.combined = perc.user + perc.sys + perc.nice + perc.wait
+ console.log printf "user: %0.2f sys: %0.2f nice: %0.2f idle: %0.2f", perc.user, perc.sys, perc.nice, perc.idle
+ prev := curr
+, 1000
Oops, something went wrong.

0 comments on commit 3affdbe

Please sign in to comment.