Skip to content

Commit 0bdd3d8

Browse files
committed
Sync the reference docs somewhat in layout
1 parent de673fb commit 0bdd3d8

File tree

12 files changed

+299
-343
lines changed

12 files changed

+299
-343
lines changed

astro.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default defineConfig({
1616
label: 'Introduction',
1717
items: [
1818
{ label: 'Getting started', link: '/introduction/getting-started/' },
19-
{ label: 'Why MetricsJS', link: '/introduction/why-metrics-js/' },
19+
{ label: 'Why MetricsJS', link: '/introduction/why-metricsjs/' },
2020
],
2121
},
2222
{

src/content/docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ editUrl: false
66
lastUpdated: false
77
hero:
88
title: Streaming metrics for Node.js
9-
tagline: Gather metrics from your dependency tree
9+
tagline: Gather metrics from your dependency tree, without dependency hell.
1010
image:
1111
file: ../../assets/metrics-js-logo.png
1212
actions:

src/content/docs/introduction/getting-started.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22
title: Getting started
33
---
44

5+
Metrics JS is an open source project for isolated instrumentation of independent modules. You can measure the things you feel are important, such as:
56

6-
7-
MetricsJS consists of three main parts:
8-
9-
1. A [client](../../reference/client/), which is the interface to produce metrics.
10-
2. A [guard](../../reference/guard/), which helps avoid excessive metric permutation creation in a stream.
11-
3. A [consumer](../../reference/prometheus-consumer/), which takes one or more metrics streams and sends data to a service such as Prometheus.
12-
13-
The consumer and guard is something you typically set up once in the root of your application, while the client is used throughout your codebase.
14-
15-
## Hello, MetricsJS
7+
- The time it takes to complete an operation.
8+
- The number of incoming requests.
9+
- The CPU load on the server.
1610

1711
Let's go through an example where we produce and read some metrics.
1812

19-
### Install dependencies
13+
## Install dependencies
2014

21-
First, install the client, guard, and Prometheus client and consumer:
15+
First, install these packages:
2216

2317
```bash
2418
npm install @metrics/client \
@@ -27,7 +21,15 @@ npm install @metrics/client \
2721
prom-client
2822
```
2923

30-
### Generate metrics
24+
MetricsJS consists of three main parts:
25+
26+
1. A [client](../../reference/client/), which is the interface to produce metrics.
27+
2. A [guard](../../reference/guard/), which helps avoid excessive metric permutation creation in a stream.
28+
3. A [consumer](../../reference/prometheus-consumer/), which takes one or more metrics streams and sends data to a service such as Prometheus.
29+
30+
The consumer and guard is something you typically set up once in the root of your application, while the client is used throughout your codebase (or that of your dependencies).
31+
32+
## Generate metrics
3133

3234
The client supports 4 types of metric creation use cases:
3335

@@ -53,7 +55,7 @@ counter.inc();
5355

5456
See the [client reference](../../reference/client/) for API documentation and more examples.
5557

56-
### Create a consumer
58+
## Create a consumer
5759

5860
Create a Prometheus consumer singleton in the root of your application, and add a guard:
5961

@@ -75,7 +77,7 @@ guard.on('drop', (metric) => {
7577
});
7678
```
7779

78-
### Pipe client data to the consumer
80+
## Pipe client data to the consumer
7981

8082
MetricsJS works on streams, so you need to pipe the client data to the consumer:
8183

@@ -96,9 +98,9 @@ Any number of streams can be piped to the consumer. In other words:
9698

9799
See the [client reference](../../reference/client/#composing-metric-streams) for code examples.
98100

99-
### Expose metrics
101+
## Read the metrics
100102

101-
Finally, expose the metrics on an endpoint in your application for the Prometheus scraper:
103+
Finally, expose the metrics on an endpoint:
102104

103105
```js
104106
app.get('/metrics', (req, res) => {
@@ -107,3 +109,5 @@ app.get('/metrics', (req, res) => {
107109
);
108110
});
109111
```
112+
113+
This endpoint can be scraped by Prometheus.

src/content/docs/introduction/why-metrics-js.md renamed to src/content/docs/introduction/why-metricsjs.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@
22
title: Why MetricsJS?
33
---
44

5-
Metrics JS is an open source project for isolated instrumentation of independent modules.
6-
7-
With Metrics JS, it's possible to instrument a Node.js module, measuring the things you feel are important such as:
8-
9-
- The time it takes to complete an operation.
10-
- The number of incoming requests.
11-
- The CPU load on the server.
12-
13-
You can measure these things without needing to know which system the metrics will be collected into. It's up to the final consumer to decide whether the metrics will be pushed to [Prometheus](../../reference/prometheus-consumer/), Data Dog or something else.
5+
With Metrics JS, it's possible to instrument a Node.js module, measuring the things you feel are important such as operation timing or counts, without needing to know which system the metrics will be collected into. It's up to the final consumer to decide whether the metrics will be pushed to Prometheus, Data Dog or something else.
146

157
## Resilient design
168

src/content/docs/reference/client.md

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,46 @@ A streaming metric producer. Allows producing counters, gauges, time series in a
99

1010
Additionally, you can pipe together different metrics streams before finally consuming them all in a single location.
1111

12+
## Usage
13+
14+
```bash
15+
npm install @metrics/client
16+
```
17+
18+
First, instantiate a new client:
19+
20+
```js
21+
const Metrics = require('@metrics/client');
22+
23+
const client = new Metrics();
24+
```
25+
26+
Next, use the client for instrumentation:
27+
28+
```js
29+
const counter = client.counter({
30+
name: 'unique_metric_name',
31+
description: 'Description of metric being collected',
32+
});
33+
34+
counter.inc();
35+
```
36+
37+
The client supports 4 types of metric creation use cases.
38+
39+
- Counters are supported via the `client.counter` method
40+
- Gauges are supported via the `client.gauge` method
41+
- Histograms are supported via the `client.histogram` method
42+
- Summaries are supported via the `client.summary` method
43+
44+
45+
Lastly, the metrics stream needs to be piped to a consumer:
46+
47+
```js
48+
client.pipe(consumer);
49+
```
50+
51+
If you're writing a library, you skip this step. Instead, expose the `client` so your users can pipe the metrics to their chosen `consumer`.
1252

1353
## API
1454

@@ -388,48 +428,6 @@ client.on('drop', (metric) => {
388428
});
389429
```
390430

391-
## Usage
392-
393-
The client is intended to be used in the following way:
394-
395-
### Step 1.
396-
397-
Instantiate a new client
398-
399-
```js
400-
const Metrics = require('@metrics/client');
401-
402-
const client = new Metrics();
403-
```
404-
405-
### Step 2.
406-
407-
Use the client for instrumentation
408-
409-
```js
410-
const counter = client.counter({
411-
name: 'unique_metric_name',
412-
description: 'Description of metric being collected',
413-
});
414-
415-
counter.inc();
416-
```
417-
418-
### Step 3.
419-
420-
Pipe collected metrics to a collector
421-
422-
```js
423-
client.pipe(consumer);
424-
```
425-
426-
The client supports 4 types of metric creation use cases.
427-
428-
- Counters are supported via the `client.counter` method
429-
- Gauges are supported via the `client.gauge` method
430-
- Histograms are supported via the `client.histogram` method
431-
- Summaries are supported via the `client.summary` method
432-
433431
## Examples
434432

435433
### Counter

src/content/docs/reference/daemon.md

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@ tableOfContents:
44
maxHeadingLevel: 4
55
---
66

7-
Daemon for collecting metrics over a network. Provides a stream for further piping of metrics.
7+
This module makes it possible to create a socket you can recieve metrics over. The socket can
8+
be of different protocols (UDP, TCP etc) but the data trasmitted over it is expected to be of
9+
the [`@metrics/metric`](../metric) type. The recieved metrics can
10+
be piped to other metric modules for further handling.
11+
12+
For sending metrics over a socket you are expected to use the [`@metrics/emitter`](../emitter) module.
13+
14+
The main purpose of this is to be able to collect metrics from multiple processes.
815

9-
## Installation
16+
## Usage
1017

1118
```bash
12-
$ npm install @metrics/daemon
19+
npm install @metrics/daemon
1320
```
1421

15-
## Example
16-
1722
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):
1823

1924
```js
@@ -28,18 +33,7 @@ daemon.pipe(client);
2833
daemon.listen();
2934
```
3035

31-
## Description
32-
33-
This module makes it possible to create a socket one can recieve metrics over. The socket can
34-
be of different protocols (UDP, TCP etc) but the data trasmitted over it is expected to be of
35-
the [`@metrics/metric`](https://github.com/metrics-js/metric) type. The recieved metrics can
36-
be piped to other metric modules for further handling.
37-
38-
For sending metrics over a socket one are expected to use the [`@metrics/emitter`](https://github.com/metrics-js/emitter) module.
39-
40-
The main purpose of this is to be able to collect metrics from multiple processes. Here is a
41-
simplified example of each worker in a cluster pushing metrics to the master and the master
42-
pushing the metric further:
36+
Here is a simplified example of each worker in a cluster pushing metrics to the master and the master pushing the metric further:
4337

4438
```js
4539
const master = () => {
@@ -81,7 +75,10 @@ if (cluster.isWorker) {
8175
See the [cluster example](https://github.com/metrics-js/daemon/tree/master/example/cluster.js)
8276
in examples for a full example.
8377

84-
## Constructor
78+
## API
79+
80+
81+
### constructor(options)
8582

8683
Create a new Daemon instance.
8784

@@ -90,26 +87,25 @@ const Daemon = require('@metrics/daemon');
9087
const daemon = new Daemon(transport, options);
9188
```
9289

93-
### transport (required)
90+
#### transport (required)
9491

9592
What type of transport to use. Supported values are:
9693

9794
* `udp` - For UDP transport.
9895

99-
### options (optional)
96+
#### options (optional)
10097

101-
An Object containing misc configuration for the selected transport. Please see each
102-
transport for which option which can be passed in.
98+
An Object containing misc configuration for the selected transport. Please see each transport for which option which can be passed in.
10399

104-
### returns
100+
#### returns
105101

106102
Returns a Readable stream in object mode.
107103

108-
## API
109-
110104
The Daemon instance has the following API:
111105

112-
### .listen()
106+
### instance methods
107+
108+
#### .listen()
113109

114110
Starts the daemon with the selected transport.
115111

src/content/docs/reference/emitter.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ tableOfContents:
44
maxHeadingLevel: 4
55
---
66

7-
Emitter for sending metrics over a network to a [daemon](../daemon).
87

9-
## Installation
8+
This module makes it possible stream metrics over a socket to a daemon. The socket can
9+
be of different protocols (UDP, TCP etc) but the data trasmitted over it is expected to be of
10+
the [`@metrics/metric`](../metric) type.
11+
12+
For recieving metrics over a socket one are expected to use the [`@metrics/daemon`](../daemon) module.
13+
14+
The main purpose of this is to be able to send metrics from multiple processes to a sentral
15+
service (daemon) for further handling.
16+
17+
## Usage
1018

1119
```bash
12-
$ npm install @metrics/emitter
20+
npm install @metrics/emitter
1321
```
1422

15-
## Example
16-
1723
Set up an emitter which connects to a daemon on UDP on port 6000 and pipes the metrics from the [`@metrics/client`](https://github.com/metrics-js/client):
1824

1925
```js
@@ -26,16 +32,7 @@ const client = new Client();
2632
client.pipe(emitter);
2733
```
2834

29-
## Description
30-
31-
This module makes it possible stream metrics over a socket to a daemon. The socket can
32-
be of different protocols (UDP, TCP etc) but the data trasmitted over it is expected to be of
33-
the [`@metrics/metric`](https://github.com/metrics-js/metric) type.
34-
35-
For recieving metrics over a socket one are expected to use the [`@metrics/daemon`](https://github.com/metrics-js/daemon) module.
36-
37-
The main purpose of this is to be able to send metrics from multiple processes to a sentral
38-
service (daemon) for further handling. Here is a simplified example of each worker in a
35+
Here is a simplified example of each worker in a
3936
cluster pushing metrics to the master and the master pushing the metric further:
4037

4138
```js
@@ -78,7 +75,9 @@ if (cluster.isWorker) {
7875
See the [cluster example](https://github.com/metrics-js/daemon/tree/master/example/cluster.js)
7976
in daemon for a full example.
8077

81-
## Constructor
78+
## API
79+
80+
### constructor(options)
8281

8382
Create a new Emitter instance.
8483

@@ -87,18 +86,18 @@ const Emitter = require('@metrics/emitter');
8786
const emitter = new Emitter(transport, options);
8887
```
8988

90-
### transport (required)
89+
#### transport (required)
9190

9291
What type of transport to use. Supported values are:
9392

9493
* `udp` - For UDP transport.
9594

96-
### options (optional)
95+
#### options (optional)
9796

9897
An Object containing misc configuration for the selected transport. Please see each
9998
transport for which option which can be passed in.
10099

101-
### returns
100+
#### returns
102101

103102
Returns a Writable stream in object mode.
104103

0 commit comments

Comments
 (0)