# statman

> Package to assist with collection of metrics, including stopwatch functionality

Latest version **1.9.1** (published 2023-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install statman
pnpm add statman
yarn add statman
bun add statman
```

## 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.9.1 |
| Published | 2023-10-24 |
| First published | 2014-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 21.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | jasonray |
| Maintainers | jasonray |
| Keywords | stopwatch, timing, performance, timer |

## Links

- npm: https://www.npmjs.com/package/statman
- Repository: https://github.com/jasonray/statman
- Homepage: https://github.com/jasonray/statman#readme
- Issues: https://github.com/jasonray/statman/issues
- npm.io page: https://npm.io/package/statman

## Dependencies (6)

- [lodash.isnull](https://npm.io/package/lodash.isnull.md) 3.0.0
- [statman-gauge](https://npm.io/package/statman-gauge.md) ^1.1.1
- [statman-meter](https://npm.io/package/statman-meter.md) 1.2.1
- [lodash.isempty](https://npm.io/package/lodash.isempty.md) ^4.4.0
- [lodash.isfunction](https://npm.io/package/lodash.isfunction.md) 3.0.9
- [statman-stopwatch](https://npm.io/package/statman-stopwatch.md) ^2.16.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.9.1 (latest) — 2023-10-24
- 1.9.0 — 2023-10-24
- 1.8.1 — 2019-10-08
- 1.8.0 — 2019-09-19
- 1.7.0 — 2019-04-08
- 1.6.0 — 2019-03-23
- 1.5.0 — 2018-04-13
- 1.4.2 — 2018-04-06
- 1.4.1 — 2018-04-06
- 1.3.0 — 2017-01-12
- 1.2.0 — 2017-01-08
- 1.1.0 — 2017-01-07
- 1.0.3 — 2017-01-07
- 1.0.2 — 2017-01-07
- 1.0.0 — 2017-01-07
- … 13 more at https://npm.io/package/statman/versions

## README

# statman

[![Node.js CI](https://github.com/jasonray/statman/actions/workflows/node.js.yml/badge.svg)](https://github.com/jasonray/statman/actions/workflows/node.js.yml)
[![on npm](http://img.shields.io/npm/v/statman.svg?style=flat)](https://www.npmjs.org/package/statman) 
[![Known Vulnerabilities](https://snyk.io/test/github/jasonray/statman-stopwatch/badge.svg)](https://snyk.io/test/github/jasonray/statman-stopwatch) 
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/52972099846944a08961a6908df7b8cc)](https://app.codacy.com/gh/jasonray/statman/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)

`statman` is a set of modules to assist with collection of metrics

# Supported metrics
* [gauge](https://github.com/jasonray/statman-gauge): represents a point in time measurement
* [meter](https://github.com/jasonray/statman-meter): measures flow, including count and average time
* [stopwatch](https://github.com/jasonray/statman-stopwatch): used to record timings

# Install it!
`statman` is decomposed into several smaller modules.  To utilize the metric modules, you have two choices
* access directly: this is recommended if there is one single metric package.  Like if you just want the stopwatch
* access via `statman`: this provides some capabilities such as a registry to easily access many metrics

## Option 1: access directly
Install using npm:
```
npm install statman-stopwatch
```

Reference in your app:
```
var Gauge = require('statman-stopwatch');
var gauge = Gauge('gauge-name');
```

## Option 2: access from `statman`
Install using npm:
```
npm install statman
```

Reference in your app:
```
var statman = require('statman');
var gauge = new statman.Gauge('gauge-name');
```

# Use it!
## Registry
`statman` provides a registry that allow for you to track your metrics.

You can manually add metrics to the registry.  For the built in metrics, you can also auto-register those while creating
```
// register a metric with a key
var metric = { ..some object.. }
statman.register('my metric name', metric)

// register a metric with implicit key = name
var metric2 = { name: 'my second metric' ..some object.. }
statman.register(metric2);

// access metric from registry
statman.registry('my metric name') //return metric
```

## Gauge
For the capabilities of `gauge` see: https://github.com/jasonray/statman-gauge

The following two approaches are equivalent
### Explicit creation of gauge
```
var gauge = statman.gauge('metric-name');
statman.regiser(gauge);
gauge.set(5);
```

### Create and register a gauge
```
statman.gauge('metric-name').set(5);   //if gauge by name 'metric-name' does not exist, create one, and set to '5'
statman.gauge('metric-name').value()   //return '5'
```

## Meter
[meter](https://github.com/jasonray/statman-meter)

## Stopwatch
[stopwatch](https://github.com/jasonray/statman-stopwatch)

# Extend it!
TODO: how to build a new metric

# Build it!
- Make sure that you have `node` and `npm` installed
- Clone source code to you local machine
- Setup dependencies: `npm install`
- run tests: `npm test`

# Roadmap
* Add meter
* Move stopwatch back to its own repo.  Sigh.
* Create reporters to output metrics
* Provide guidance how to hook with HTTP/TCP/async calls
* Provide hook to register with express
* Integrate with visualizations
* Provide web interface to access metrics

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