# system-usage

> simple way to lookup cpu usage for linux, also work with plot.ly

Latest version **0.1.1** (published 2014-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install system-usage
pnpm add system-usage
yarn add system-usage
bun add system-usage
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2014-11-23 |
| First published | 2014-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sung Wook Moon |
| Maintainers | swmoon203 |
| Keywords | linux, cpu, usage, plotly, memory, realtime |

## Links

- npm: https://www.npmjs.com/package/system-usage
- Repository: https://github.com/swmoon203/nodejs-system-usage
- Issues: https://github.com/swmoon203/nodejs-system-usage/issues
- npm.io page: https://npm.io/package/system-usage

## Dependencies (3)

- [plotly](https://npm.io/package/plotly.md) 0.2.13
- [readable-stream](https://npm.io/package/readable-stream.md) ~1.0.26
- [date-format-lite](https://npm.io/package/date-format-lite.md) 0.5.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2014-11-23
- 0.1.0 — 2014-11-23

## README

# system-usage (for linux)

##Installation
```javascript
npm install system-usage 
```

##Usage
```javascript
var usage = require("system-usage");

var stream = usage.createStream();
stream.pipe("cpu", process.stdout);
```

##Option
```javascript
var option = { 
	interval: 300,
	percent: true 
};

var stream = usage.createStream(option);
```
>`interval`: ms
>
> `percent`: FALSE: 0.0 ~ 1.0, TRUE: 0 ~ 100


##Methods
###readStat(callback) return { cpu: { idle, total }, cpu0, memory, ...
```javascript
usage.readStat(function(results) {
    console.log(results);
});
```
###availableTypes(callback) return [ 'memory', 'cpu', 'cpu0', ... ]
```javascript
usage.availableTypes(function(list) {
	console.log(list);
});
```
###createStream(option) return stream
```javascript
var stream = usage.createStream();
```
###stream.pipe(type, writable)
```javascript
var stream = usage.createStream();
stream.pipe("cpu", process.stdout);
```

##Plot.ly 

> Live Streaming Example from https://www.npmjs.org/package/plotly

```javascript
Plotly.plot(data, graphOptions, function (err, resp) {
    if (err) return console.log("ERROR", err)

    console.log(resp)

    var plotlystream = Plotly.stream(token, function () {})
    var signalstream = usage.createStream(); // <-


    plotlystream.on("error", function (err) {
        signalstream.destroy()
    })

    // Okay - stream to our plot!
    signalstream.pipe("cpu", plotlystream)
})
```

####For multiple trace
```javascript
Plotly.plot(data, graphOptions, function (err, resp) {
    if (err) return console.log("ERROR", err)

    console.log(resp)

    var signalstream = usage.createStream(); // <-

    var cpustream = Plotly.stream(token, function () {})
    cpustream.on("error", function (err) {
        signalstream.destroy()
    })

    var memorystream = Plotly.stream(token2, function () {})
    memorystream.on("error", function (err) {
        signalstream.destroy()
    })
    
    // Okay - stream to our plot!
    signalstream.pipe("cpu", cpustream)
    signalstream.pipe("memory", memorystream)
})
```

###plotlyStream(username, apiKey, data, graphOptions, callback)
```javascript
var graphOptions = {
    "filename": "usage"
  , "fileopt": "overwrite"
  , "world_readable": true
};
usage.plotlyStream(username, apiKey, [token1, token2, token3], graphOptions, function(err, msg) {
	console.log(msg);
});
```
OR
```javascript
var graphOptions = {
    "filename": "usage"
  , "fileopt": "overwrite"
  , "world_readable": true
};
var data = [
    {
    	x: [], y: [], 
    	name: "CPU%", 
    	type: "cpu", 
    	stream: { 	
    		token: token1, 
			maxpoints: 50 
		}
	},
    {
    	x: [], y: [], 
    	name: "Memory%", 
    	type: "memory", 
    	stream: { 	
    		token: token2, 
			maxpoints: 50 
		}
	}
];
usage.plotlyStream(username, apiKey, data, graphOptions, function(err, msg) {
	console.log(msg);
});
```

Demo https://plot.ly/~mtjddnr/16

---
_Source: https://npm.io/package/system-usage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
