# opsdash-client

> NodeJS client for the OpsDash Server Monitor

Latest version **0.3.0** (published 2015-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install opsdash-client
pnpm add opsdash-client
yarn add opsdash-client
bun add opsdash-client
```

## 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.3.0 |
| Published | 2015-10-27 |
| First published | 2015-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Patrick Daether, https://github.com/pdaether |
| Maintainers | pdaether |
| Keywords | OpsDash, monitoring |

## Links

- npm: https://www.npmjs.com/package/opsdash-client
- Repository: https://github.com/pdaether/opsdash-client
- Homepage: https://github.com/pdaether/opsdash-client#readme
- Issues: https://github.com/pdaether/opsdash-client/issues
- npm.io page: https://npm.io/package/opsdash-client

## Dependencies (2)

- [usage](https://npm.io/package/usage.md) ^0.7.1
- [request](https://npm.io/package/request.md) ^2.65.0

## Recent versions

- 0.3.0 (latest) — 2015-10-27
- 0.2.1 — 2015-10-26
- 0.2.0 — 2015-10-26
- 0.1.0 — 2015-10-25

## README

# OpsDash Client for NodeJS

This is a node client for the [OpsDash Server Monitor](https://www.opsdash.com/). You can report process metrics like memory and cpu usage and of course your own individual metrics.

It requires NodeJS >= 4.0.0

![Memory example](http://pdaether.github.io/images/opsdash-client/opsDash_node_memory.png)

![Uptime example](http://pdaether.github.io/images/opsdash-client/opsDash_node_uptime.png)

## Install

```bash
npm install --save opsdash-client
```

## Setup

```javascript
let opsDashClient = require('opsdash-client')

let opsDashReporter = opsDashClient({
  server: 'http://yourOpsDashDomain:8080',
  interval: 30,
  source: 'expressApp-' + opsDashClient.hostname
})
```

The option object can have the following attributes:


- **server:** Address of your  OpsDash server including the port.
- **interval:** Default interval for sending metrics in seconds.
- **reportProcessMetrics:** Boolean, default `true`. Should the opsDashClient automatically send process reports (details see below).
- **source:** Name of the source.

## Reporting metrics of your node process

The opsDashClient can send the following metrics of your node process:

- **memory.rss**
- **memory.heapUsed**
- **memory.heapTotal**
- **cpu** (CPU usage in %)
- **uptime** (uptime of your node process in seconds - great to identify crashes or restarts)

If you instantiate your reporter with `reportProcessMetrics` set to `true`, then this metrics will be reported automatically (default).

Otherwise you can start sending this metrics manually:

```javascript
opsDashReporter.startProcessReporting()
```

If you want to stop sending this metrics:

```javascript
opsDashReporter.stopProcessReporting()
```

### Sending only selected process metrics

If you don't want to send all available process metrics, you can start them manually.
For example, to only report the cpu usage:

```javascript
opsDashReporter.addMetric(
  'cpu',
  {type: 'callback', start:true},
  opsDashClient.processReporter.cpu
)
```

## Reporting individual metrics

Currently three different types of values are supported:

- Simple values like counters
- Setting values with a synchronous function
- Setting values with an asynchronous callback

To add a new metric use the `opsDashReporter.addMetric(name, options, callback)` method.

### Simple values

Setup:

```javascript
//Add new metric and start reporting
opsDashReporter.addMetric(
  'numberOfLogins',
  {type: 'value', start: true, reset:true}
)
```
Options:

- **type:** In case of simple values, this must be `value`
- **start:** Boolean, should we stat the reporting automatically?
- **reset:** Boolean. If `true`, the value will be reseted after every report interval, default `true`
- **startValue:** The initial value of your metric, default `0`
- **interval:** The reporting interval in seconds. If not set, the default interval will be used.

Increase the value:

```javascript
//will increase the value by 1:
opsDashReporter.incMetric('numberOfLogins')

//will increase the value by number
opsDashReporter.incMetric('numberOfLogins', number)

//will set the value to number
opsDashReporter.setMetricValue('numberOfLogins', number)
```


### Synchronous and asynchronous functions for retrieving values

Setup:

```javascript
//Add new metric and start reporting
opsDashReporter.addMetric(
  'numberOfLogins',
  {type: 'callback', start: true, reset:true},
  yourCallbackFunction
)
```
In this case you provide a callback function to get the current value of your metric.

If this is a synchronous function, this callback must not have any parameters and must return the value of your metric.

If this is a asynchronous function, the function must have a callback function in the form of `function(err, result)` as the only parameter.

## Error Handling

The opsDashClient emits a `error`-Event:

```javascript
opsDashReporter.on('error', function(err){
  console.error(err);
})
```

## TODO

- Support Basic Auth
- Improve error handling
- Check usage in cluster mode

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