1.3.7 • Published 3 years ago

node-os-utils v1.3.7

Weekly downloads
10,156
License
MIT
Repository
github
Last release
3 years ago

Description

monitor vital signs of your server :

  • CPU average usage
  • Free and used drive space
  • Free and used memory space
  • Operating System
  • All processes running
  • TTY/SSH opened
  • Total opened files
  • Network speed (input and output)

node-os-utils

JavaScript Style Guide Build Status NPM Version NPM Downloads

An operating system utility library. Some methods are wrappers of node libraries and others are calculations made by the module.

os-utils extended

Installation

One line installation with npm.

$ npm install node-os-utils --save

Then in your code

Example

var osu = require('node-os-utils')
var cpu = osu.cpu

var count = cpu.count() // 8

cpu.usage()
  .then(cpuPercentage => {
    console.log(cpuPercentage) // 10.38
  })

var osCmd = osu.osCmd

osCmd.whoami()
  .then(userName => {
    console.log(userName) // admin
  })

Configuration

require('node-os-utils').options

Default settings:

  • NOT_SUPPORTED_VALUE is not supported. os not supported, return value.
  • INTERVAL is 1000 millisecond. Represents the refresh of the cpu and network workers.

:warning: If this module uses too much CPU, set the INTERVAL value to 10000 or more.

Info

If you have not supported in some categories, your OS configuration is not supported for this option.

You can use require('node-os-utils').isNotSupported() to decide not supported.

var osu = require('node-os-utils')
var osCmd = osu.osCmd

osCmd
  .topCpu()
  .then(function(res){
    if(osu.isNotSupported(res)){
      // Handle 'not supported'
    }else{
      // Things to do...
    }
  })

Usage

The following methods are available:

require('node-os-utils').cpu

cpu.average():object

CPU average

var osu = require('node-os-utils')
var cpu = osu.cpu

var info = cpu.average()

console.log(info)
{ totalIdle: 33526410,
  totalTick: 37460330,
  avgIdle: 4190801.25,
  avgTotal: 4682541.25 }

cpu.usage(interval):Promise(number)

CPU average usage

  • interval: number - interval millisecond. defaulta: 1000
var osu = require('node-os-utils')
var cpu = osu.cpu

cpu.usage()
  .then(info => {
    console.log(info)
  })
10.06

cpu.free(interval):Promise(number)

cpu free percentage

  • interval: number - interval millisecond. defaulta: 1000
var osu = require('node-os-utils')
var cpu = osu.cpu

cpu.free()
  .then(info => {
    console.log(info)
  })
89.26

cpu.count():number

cpu.model():string

cpu.loadavg():Arraynumber

cpu.loadavgTime(time):number

  • time: number - 1, 5 or 15 minutes, defaulta: 1

require('node-os-utils').drive

drive.info():Promise(Object)

drive info

var osu = require('node-os-utils')
var drive = osu.drive

drive.info()
  .then(info => {
    console.log(info)
  })
{ totalGb: '464.8',
  usedGb: '147.7',
  freeGb: '316.9',
  usedPercentage: '31.8',
  freePercentage: '68.2' }

drive.free():Promise(Object)

{ totalGb: '464.8', freeGb: '316.9', freePercentage: '68.2' }

drive.used():Promise(Object)

{ totalGb: '464.8', usedGb: '316.9', usedPercentage: '68.2' }

require('node-os-utils').mem

mem.info():Promise(Object)

memory info

var osu = require('node-os-utils')
var mem = osu.mem

mem.info()
  .then(info => {
    console.log(info)
  })
{ totalMemMb: 16384,
  usedMemMb: 13403.41,
  freeMemMb: 2980.59,
  freeMemPercentage: 18.19 }

mem.free():Promise(Object)

{ totalMemMb: 16384, freeMemMb: 3033.63 }

mem.used():Promise(Object)

{ totalMemMb: 16384, usedMemMb: 13421.15 }

mem.totalMem():number

17179869184

require('node-os-utils').netstat

netstat.stats():Promise(ArrayObject)

var osu = require('node-os-utils')
var netstat = osu.netstat

netstat.stats()
  .then(info => {
    console.log(info)
  })
[ { interface: 'lo',
    inputBytes: '731508412',
    outputBytes: '731508412' },
  { interface: 'eth0',
    inputBytes: '1356471479',
    outputBytes: '26631036763' } ]

netstat.inOut(interval):Promise(Object)

  • interval: number - interval millisecond. defaulta: 1000
var osu = require('node-os-utils')
var netstat = osu.netstat

netstat.inOut()
  .then(info => {
    console.log(info)
  })
{ total: { inputMb: 0.02, outputMb: 1.22 },
  eth0: { inputMb: 0.02, outputMb: 1.22 } }

require('node-os-utils').openfiles

openfiles.openFd():Promise(number)

Total opened files

1088

require('node-os-utils').os

os.oos():Promise(string)

original operating system

Mac OS X 10.12.5
Red Hat 7.3

os.platform():string

os.uptime():number - (seconds)

os.ip():string

os.hostname():string

os.type():string

os.arch():string


require('node-os-utils').proc

proc.totalProcesses():Promise(number)

proc.zombieProcesses():Promise(number)


require('node-os-utils').users

users.openedCount():Promise(number)

TTY/SSH opened


require('node-os-utils').osCmd

osCmd.topCpu():Promise(string)

osCmd.topMem():Promise(string)

osCmd.vmstats():Promise(string)

......

var bucket = require('./bucket')
var exec = require('./exec')
var wrapExec = exec.wrapExec

bucket.osCmd = {
  topCpu: wrapExec('ps -eo pcpu,user,args --no-headers | sort -k 1 -n | tail -n 10 | sort -k 1 -nr | cut -c 1-70'),
  topMem: wrapExec('ps -eo pmem,pid,cmd | sort -k 1 -n | tail -n 10 | sort -k 1 -nr | cut -c 1-70'),
  vmstats: wrapExec('vmstat -S m'),
  processesUsers: wrapExec('ps hax -o user | sort | uniq -c'),
  diskUsage: wrapExec('df -h'),
  who: wrapExec('who'),
  whoami: wrapExec('whoami'),
  openPorts: wrapExec('lsof -Pni4 | grep ESTABLISHED'),
  ifconfig: wrapExec('ifconfig')
}

License

MIT. Copyright (c).

speckybotintegrador-hgfpaytudlio-clientzbench-es-benchmarkingviperx-npm@hotfusion/servicesuper-rest-api@everything-registry/sub-chunk-2307looper-streaming-alphaxianyu-robots3-file-scan-catsharding-statssharding-stats-colorservice_logserv-monicordvitomonitorvanity-wallet-consolememo-watchermeoaw.jslnp_ws_monitorliyabotz-apilogr-node-clientlog-obj-jsonjsontwice.iolooper-streaminggs-sysinfohaxball-serverhyperfy-serverkibana-reportskeyskinhelpers-fnnecroatomicbotlwstatusnode_linkroom_utilitiesnodejs-system-infoopex-utilsnvr-jsnfw-corepaymentportalssnode-red-contrib-monitorcpu-nocolapc-web-dashpaydisininew-rvtshwrvtshwslice-linesignalk-healthcheckudirptypedapi-serverthsq-agenttmui-clitres-comas@autobits/influxdb-client@awefly/faas-js-runtime@alwaysai/device-agent@abyss-project/monitor@differentialhq/core@differentialhq/sdkw-sysmonitor@hocuspocus/extension-monitor@infinitebrahmanuniverse/nolb-node-o@enmanuel_mag/mhwlib@hypsibius/faas-js-runtime@kepler-io/cli@saltfish-bot/plugin-system@scramjet/load-check@stencila/sparkla@observerx/panel-server@pankaj_bhosle/health_check@sms0nhaaa/colyseus-monitor@sms0nhaaa/t-monitor@snaplet/snapshot@dnglchlk/dngl-raccbot@condor-labs/health-middleware@condor-labs/metrics@colyseus/monitor@colyseus/toolseasly-discordjsendframe-functionsespmcespmc-statuseye-rest@trythis/treblle-expressfaas-js-runtime@vominhtam1210/colyseus-monitor@vroskus/library-healthabyss_monitor_core@zsdxh/d-app-pcajbotz-api@yizhanzhang/monitor-cubebeibei-coreblitzo-test-srvapied-piperatomonitorautomationnpmtestcongiola-ybcortexsocollectors-frameworkdbm2deploy-with-terraform-appdoback
1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.8

5 years ago

1.0.7

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago