-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: deduplicate reference documentation
- Loading branch information
Showing
1 changed file
with
4 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,12 @@ | ||
# @metrics/daemon | ||
|
||
Daemon for collecting metrics over a network. Provides a stream for further piping of metrics. | ||
|
||
[![Dependencies](https://img.shields.io/david/metrics-js/daemon.svg)](https://david-dm.org/metrics-js/daemon) | ||
[![GitHub Actions status](https://github.com/metrics-js/daemon/workflows/Run%20Lint%20and%20Tests/badge.svg)](https://github.com/metrics-js/daemon/actions?query=workflow%3A%22Run+Lint+and+Tests%22) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/metrics-js/daemon/badge.svg?targetFile=package.json)](https://snyk.io/test/github/metrics-js/daemon?targetFile=package.json) | ||
|
||
## Installation | ||
|
||
```bash | ||
$ npm install @metrics/daemon | ||
``` | ||
|
||
## Example | ||
|
||
Set up a daemon with UDP on port 6000 as transport and pipes the incomming metrics into the [`@metrics/client`](https://github.com/metrics-js/client): | ||
|
||
```js | ||
const Daemon = require('@metrics/daemon'); | ||
const Client = require('@metrics/client'); | ||
|
||
const daemon = new Daemon('udp', { port: 6000 }); | ||
const client = new Client(); | ||
|
||
daemon.pipe(client); | ||
|
||
daemon.listen(); | ||
``` | ||
|
||
## Description | ||
|
||
This module makes it possible to create a socket one can recieve metrics over. The socket can | ||
be of different protocols (UDP, TCP etc) but the data trasmitted over it is expected to be of | ||
the [`@metrics/metric`](https://github.com/metrics-js/metric) type. The recieved metrics can | ||
be piped to other metric modules for further handling. | ||
|
||
For sending metrics over a socket one are expected to use the [`@metrics/emitter`](https://github.com/metrics-js/emitter) module. | ||
|
||
The main purpose of this is to be able to collect metrics from multiple processes. Here is a | ||
simplified example of each worker in a cluster pushing metrics to the master and the master | ||
pushing the metric further: | ||
|
||
```js | ||
const master = () => { | ||
const daemon = new Daemon('udp', { port: 6000 }); | ||
const client = new Client(); | ||
|
||
daemon.pipe(client); | ||
|
||
daemon.listen(); | ||
}; | ||
|
||
const worker = () => { | ||
const emitter = new Emitter('udp', { port: 6000 }); | ||
const client = new Client(); | ||
|
||
client.pipe(emitter); | ||
|
||
client.metric({ | ||
name: `worker_${cluster.worker.id}`, | ||
description: `Worker number: ${cluster.worker.id}`, | ||
value: 1, | ||
}); | ||
}; | ||
|
||
const workers = []; | ||
|
||
if (cluster.isMaster) { | ||
for (let i = 0; i < (os.cpus().length - 1); i++) { | ||
workers.push(cluster.fork()); | ||
} | ||
master(); | ||
} | ||
|
||
if (cluster.isWorker) { | ||
worker(); | ||
} | ||
``` | ||
|
||
See the [cluster example](https://github.com/metrics-js/daemon/tree/master/example/cluster.js) | ||
in examples for a full example. | ||
|
||
## Constructor | ||
|
||
Create a new Daemon instance. | ||
|
||
```js | ||
const Daemon = require('@metrics/daemon'); | ||
const daemon = new Daemon(transport, options); | ||
``` | ||
|
||
### transport (required) | ||
|
||
What type of transport to use. Supported values are: | ||
|
||
* `udp` - For UDP transport. | ||
|
||
### options (optional) | ||
|
||
An Object containing misc configuration for the selected transport. Please see each | ||
transport for which option which can be passed in. | ||
|
||
### returns | ||
|
||
Returns a Readable stream in object mode. | ||
|
||
## API | ||
|
||
The Daemon instance has the following API: | ||
|
||
### .listen() | ||
|
||
Starts the daemon with the selected transport. | ||
|
||
## Transports | ||
|
||
The following transports is supported: | ||
|
||
### UDP | ||
Daemon for collecting metrics over a network. Provides a stream for further piping of metrics. | ||
|
||
UDP as a transport can be enabled by providing `udp` to the transport argument on the | ||
Daemon constructor. The UDP transport takes the following options (passed to the options | ||
argument on the Daemon constructor): | ||
## Usage | ||
|
||
* **port** - `Number` - The port to bind to. Default: 40400. | ||
* **address** - `String` - The address to bind to. Default: localhost. | ||
* **logger** - `Function` - Any logger that implements the methods `trace`, `debug`, `info`, `warn`, `error` and `fatal`. Under the hood [abslog](https://www.npmjs.com/package/abslog) is used. See that module for further information. If no logger is passed in, nothing will be logged. | ||
- [Getting started with MetricsJS](https://metrics-js.github.io/introduction/getting-started/). | ||
- [Reference documentaiton for `@metrics/daemon`](https://metrics-js.github.io/reference/daemon/). |