# @nearform/stats

> [![Build Status](https://travis-ci.org/nearform/stats.svg?branch=master)](https://travis-ci.org/nearform/stats)

Latest version **1.0.1** (published 2017-07-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @nearform/stats
pnpm add @nearform/stats
yarn add @nearform/stats
bun add @nearform/stats
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-07-21 |
| First published | 2017-07-18 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Glen Keane |
| Maintainers | thekemkid, sigkell, conoro, damianberesford, matteo.collina, davidmarkclements, nearformer |
| Keywords | Probe, stats, process, profile, gc, event-loop |

## Links

- npm: https://www.npmjs.com/package/@nearform/stats
- npm.io page: https://npm.io/package/@nearform/stats

## Dependencies (4)

- [hyperid](https://npm.io/package/hyperid.md) ^1.2.0
- [loopbench](https://npm.io/package/loopbench.md) ^1.2.0
- [reinterval](https://npm.io/package/reinterval.md) ^1.1.0
- [gc-profiler](https://npm.io/package/gc-profiler.md) ^1.4.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-07-21
- 1.0.0 — 2017-07-19
- 0.0.1 — 2017-07-18
- 0.0.0 — 2017-07-18

## README

# stats

[![Build Status](https://travis-ci.org/nearform/stats.svg?branch=master)](https://travis-ci.org/nearform/stats)

Collect stats about your node.js process.

## Intro to the nearform stats tooling

Created with the purpose to make creating visualisations about your process easy. At nearform, we achieve this using the modules [stats](http://github.com/nearform/stats) [stats-to-elasticsearch](http://github.com/nearform/stats-to-elasticsearch) and [create-stats-dashboard](http://github.com/nearform/create-stats-dashboard). This makes it very easy to collect process stats in elasticsearch and visualise them in a dashboard in kibana, similar to that below:

<img src='./assets/dashboard-screenshot.png' alt='a kibana stats dashboard screenshot'>

Once your dashboard is setup with create-stats-dashboard, all you should need to do is require the stats-to-elasticsearch module and point it at the dashboard to get cool (and useful) visualisations!

## Installation

```
npm install --save @nearform/stats
```

### Usage

This module exports a function which instantiates an event emitter which emits a single event, `stats`. This event emitter has two functions which can be used to start and stop probing for statistics, `start()` and `stop()`. Listen to the `stats` event to get useful process statistics.

### Example:
```js
const StatsProducer = require('@nearform/stats')
const statsProducer = new StatsProducer()
statsProducer.start()
statsProducer.on('stats', function (stats) {
  // so something with these stats
})

// some time later...
statsProducer.stop()
```

### API

`StatsProducer(opts)`

Returns an event emitter which emits a `stats` event containing useful stats.

- opts: an `object` which can contain the following properties to set for generating statistics
  - sampleInterval: a `number` representing the amount of seconds to take a sample when running. Defaults to 5 seconds.
  - eventLoopSampleInterval: the interval at which the eventLoop should be sampled, defaults to 500.
  - eventLoopLimit: the maximum amount of delay that is tolerated before overLimit is detected as true, defaults to 50.
  - tags: an array of user defined strings to tag your stats with

The StatsProducer event emitter which is returned has the following methods.

`statsProducer.start()` - starts the stats producer listening and producing stats.

`statsProducer.stop()` - stops producing stats.

### Stat object

The stat object which is emitted has the following properties:

- `tags`: the array of user defined strings defined in the constructor to tag your stats with
- `id`: A uuid generated at start up for this stats producer
- `timestamp`: The time the stats were generated
- `process`: an object with the following properties extracted from the global process object. See the official node documentation for more information on these properties.
  - `cpuUsage`: This is a function on the process object which is invoked to fill in the value.
  - `memoryUsage`: This is a function on the process object which is invoked to fill in the value.
  - `uptime`: This is a function on the process object which is invoked to fill in the value.
  - `title`
  - `pid`
  - `release`
  - `versions`
  - `argv`
  - `execArgv`
  - `execPath`
- `system`: an object with the following properties extracted from the os module. See the official node documentation for more information on these properties.
  - `cpus`: This is a function on the os module which is invoked at initialisation to fill in the value. This is not expected to change.
  - `uptime`:  This is a function on the os module which is invoked to fill in the value.
  - `freemem`: This is a function on the os module which is invoked to fill in the value.
  - `loadavg`: This is a function on the os module which is invoked to fill in the value.
  - `platform`
  - `arch`
- `eventLoop`: this is an object which contains the following properties extracted from benchmarking the eventloop.
  - `delay`: The delay in milliseconds (and fractions) from the expected eventloop run. It might be negative (in older nodes).
  - `limit`: The maximum amount of delay that is tolerated before overLimit becomes true.
  - `overlimit`: true if the delay > limit.
- `gcRuns`: an array with objects added after every gc run. see [here](http://npm.im/gc-profiler) to see the format of the objects added

## Useful links

- [stats](http://github.com/nearform/stats) - makes generating the stats to be visualised a breeze!
- [stats-to-elasticsearch](http://github.com/nearform/stats-to-elasticsearch) - makes sending the stats to es a breeze!
- [create-stats-dashboard](http://github.com/nearform/create-stats-dashboard) - makes creating your kibana dashboard a breeze!

### License

Apache 2.0

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