@libp2p/prometheus-metrics 2.0.8 → 2.0.9-025c082a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -26
- package/dist/src/index.d.ts +72 -11
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +70 -9
- package/dist/src/index.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +72 -11
- package/dist/typedoc-urls.json +0 -8
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# @libp2p/prometheus-metrics <!-- omit in toc -->
|
|
2
|
-
|
|
3
1
|
[](http://libp2p.io/)
|
|
4
2
|
[](https://discuss.libp2p.io)
|
|
5
3
|
[](https://codecov.io/gh/libp2p/js-libp2p)
|
|
@@ -7,27 +5,7 @@
|
|
|
7
5
|
|
|
8
6
|
> Collect libp2p metrics for scraping by Prometheus or Graphana
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- [Install](#install)
|
|
13
|
-
- [Usage](#usage)
|
|
14
|
-
- [Queries](#queries)
|
|
15
|
-
- [Data sent/received](#data-sentreceived)
|
|
16
|
-
- [CPU usage](#cpu-usage)
|
|
17
|
-
- [Memory usage](#memory-usage)
|
|
18
|
-
- [DHT query time](#dht-query-time)
|
|
19
|
-
- [TCP transport dialer errors](#tcp-transport-dialer-errors)
|
|
20
|
-
- [API Docs](#api-docs)
|
|
21
|
-
- [License](#license)
|
|
22
|
-
- [Contribution](#contribution)
|
|
23
|
-
|
|
24
|
-
## Install
|
|
25
|
-
|
|
26
|
-
```console
|
|
27
|
-
$ npm i @libp2p/prometheus-metrics
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Usage
|
|
8
|
+
# About
|
|
31
9
|
|
|
32
10
|
Configure your libp2p node with Prometheus metrics:
|
|
33
11
|
|
|
@@ -93,17 +71,112 @@ libp2p_kad_dht_lan_query_time_seconds
|
|
|
93
71
|
rate(libp2p_tcp_dialer_errors_total[30s])
|
|
94
72
|
```
|
|
95
73
|
|
|
96
|
-
##
|
|
74
|
+
## Example
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
78
|
+
|
|
79
|
+
const metrics = prometheusMetrics()()
|
|
80
|
+
const myMetric = metrics.registerMetric({
|
|
81
|
+
name: 'my_metric',
|
|
82
|
+
label: 'my_label',
|
|
83
|
+
help: 'my help text'
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
myMetric.update(1)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Example
|
|
90
|
+
|
|
91
|
+
A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
95
|
+
|
|
96
|
+
const metrics = prometheusMetrics()()
|
|
97
|
+
const myMetric = metrics.registerMetric({
|
|
98
|
+
name: 'my_metric',
|
|
99
|
+
label: 'my_label',
|
|
100
|
+
help: 'my help text',
|
|
101
|
+
calculate: async () => {
|
|
102
|
+
// do something expensive
|
|
103
|
+
return 1
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Example
|
|
109
|
+
|
|
110
|
+
If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
114
|
+
|
|
115
|
+
const metrics = prometheusMetrics()()
|
|
116
|
+
const myMetricGroup = metrics.registerMetricGroup({
|
|
117
|
+
name: 'my_metric_group',
|
|
118
|
+
label: 'my_label',
|
|
119
|
+
help: 'my help text'
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
myMetricGroup.increment({ my_label: 'my_value' })
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
There are specific metric groups for tracking libp2p connections and streams:
|
|
126
|
+
|
|
127
|
+
## Example
|
|
128
|
+
|
|
129
|
+
Track a newly opened multiaddr connection:
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
133
|
+
import { createLibp2p } from 'libp2p'
|
|
134
|
+
|
|
135
|
+
const metrics = prometheusMetrics()()
|
|
136
|
+
|
|
137
|
+
const libp2p = await createLibp2p({
|
|
138
|
+
metrics: metrics,
|
|
139
|
+
})
|
|
140
|
+
// set up a multiaddr connection
|
|
141
|
+
const connection = await libp2p.dial('multiaddr')
|
|
142
|
+
const connections = metrics.trackMultiaddrConnection(connection)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Example
|
|
146
|
+
|
|
147
|
+
Track a newly opened stream:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
151
|
+
import { createLibp2p } from 'libp2p'
|
|
152
|
+
|
|
153
|
+
const metrics = prometheusMetrics()()
|
|
154
|
+
|
|
155
|
+
const libp2p = await createLibp2p({
|
|
156
|
+
metrics: metrics,
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
const stream = await connection.newStream('/my/protocol')
|
|
160
|
+
const streams = metrics.trackProtocolStream(stream)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
# Install
|
|
164
|
+
|
|
165
|
+
```console
|
|
166
|
+
$ npm i @libp2p/prometheus-metrics
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
# API Docs
|
|
97
170
|
|
|
98
171
|
- <https://libp2p.github.io/js-libp2p/modules/_libp2p_prometheus_metrics.html>
|
|
99
172
|
|
|
100
|
-
|
|
173
|
+
# License
|
|
101
174
|
|
|
102
175
|
Licensed under either of
|
|
103
176
|
|
|
104
177
|
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
105
178
|
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
106
179
|
|
|
107
|
-
|
|
180
|
+
# Contribution
|
|
108
181
|
|
|
109
182
|
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,10 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* @module libp2p-prometheus-metrics
|
|
4
|
+
* Configure your libp2p node with Prometheus metrics:
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* ```js
|
|
7
|
+
* import { createLibp2p } from 'libp2p'
|
|
8
|
+
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
9
|
+
*
|
|
10
|
+
* const node = await createLibp2p({
|
|
11
|
+
* metrics: prometheusMetrics()
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Then use the `prom-client` module to supply metrics to the Prometheus/Graphana client using your http framework:
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import client from 'prom-client'
|
|
19
|
+
*
|
|
20
|
+
* async handler (request, h) {
|
|
21
|
+
* return h.response(await client.register.metrics())
|
|
22
|
+
* .type(client.register.contentType)
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* All Prometheus metrics are global so there's no other work required to extract them.
|
|
27
|
+
*
|
|
28
|
+
* ### Queries
|
|
29
|
+
*
|
|
30
|
+
* Some useful queries are:
|
|
31
|
+
*
|
|
32
|
+
* #### Data sent/received
|
|
33
|
+
*
|
|
34
|
+
* ```
|
|
35
|
+
* rate(libp2p_data_transfer_bytes_total[30s])
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* #### CPU usage
|
|
39
|
+
*
|
|
40
|
+
* ```
|
|
41
|
+
* rate(process_cpu_user_seconds_total[30s]) * 100
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* #### Memory usage
|
|
45
|
+
*
|
|
46
|
+
* ```
|
|
47
|
+
* nodejs_memory_usage_bytes
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* #### DHT query time
|
|
51
|
+
*
|
|
52
|
+
* ```
|
|
53
|
+
* libp2p_kad_dht_wan_query_time_seconds
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* or
|
|
57
|
+
*
|
|
58
|
+
* ```
|
|
59
|
+
* libp2p_kad_dht_lan_query_time_seconds
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* #### TCP transport dialer errors
|
|
63
|
+
*
|
|
64
|
+
* ```
|
|
65
|
+
* rate(libp2p_tcp_dialer_errors_total[30s])
|
|
66
|
+
* ```
|
|
8
67
|
*
|
|
9
68
|
* @example
|
|
10
69
|
*
|
|
@@ -20,10 +79,11 @@
|
|
|
20
79
|
*
|
|
21
80
|
* myMetric.update(1)
|
|
22
81
|
* ```
|
|
23
|
-
* A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped:
|
|
24
82
|
*
|
|
25
83
|
* @example
|
|
26
84
|
*
|
|
85
|
+
* A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped:
|
|
86
|
+
*
|
|
27
87
|
* ```typescript
|
|
28
88
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
29
89
|
*
|
|
@@ -39,10 +99,10 @@
|
|
|
39
99
|
* })
|
|
40
100
|
* ```
|
|
41
101
|
*
|
|
42
|
-
* If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead:
|
|
43
|
-
*
|
|
44
102
|
* @example
|
|
45
103
|
*
|
|
104
|
+
* If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead:
|
|
105
|
+
*
|
|
46
106
|
* ```typescript
|
|
47
107
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
48
108
|
*
|
|
@@ -58,14 +118,14 @@
|
|
|
58
118
|
*
|
|
59
119
|
* There are specific metric groups for tracking libp2p connections and streams:
|
|
60
120
|
*
|
|
61
|
-
* Track a newly opened multiaddr connection:
|
|
62
121
|
* @example
|
|
63
122
|
*
|
|
123
|
+
* Track a newly opened multiaddr connection:
|
|
124
|
+
*
|
|
64
125
|
* ```typescript
|
|
65
126
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
66
127
|
* import { createLibp2p } from 'libp2p'
|
|
67
128
|
*
|
|
68
|
-
*
|
|
69
129
|
* const metrics = prometheusMetrics()()
|
|
70
130
|
*
|
|
71
131
|
* const libp2p = await createLibp2p({
|
|
@@ -76,9 +136,10 @@
|
|
|
76
136
|
* const connections = metrics.trackMultiaddrConnection(connection)
|
|
77
137
|
* ```
|
|
78
138
|
*
|
|
79
|
-
* Track a newly opened stream:
|
|
80
139
|
* @example
|
|
81
140
|
*
|
|
141
|
+
* Track a newly opened stream:
|
|
142
|
+
*
|
|
82
143
|
* ```typescript
|
|
83
144
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
84
145
|
* import { createLibp2p } from 'libp2p'
|
|
@@ -93,7 +154,7 @@
|
|
|
93
154
|
* const streams = metrics.trackProtocolStream(stream)
|
|
94
155
|
* ```
|
|
95
156
|
*/
|
|
96
|
-
import { type DefaultMetricsCollectorConfiguration, type Registry } from 'prom-client';
|
|
157
|
+
import { type DefaultMetricsCollectorConfiguration, type Registry, type RegistryContentType } from 'prom-client';
|
|
97
158
|
import type { CalculatedMetricOptions, Metrics } from '@libp2p/interface/metrics';
|
|
98
159
|
export interface PrometheusMetricsInit {
|
|
99
160
|
/**
|
|
@@ -109,7 +170,7 @@ export interface PrometheusMetricsInit {
|
|
|
109
170
|
/**
|
|
110
171
|
* prom-client options to pass to the `collectDefaultMetrics` function
|
|
111
172
|
*/
|
|
112
|
-
defaultMetrics?: DefaultMetricsCollectorConfiguration
|
|
173
|
+
defaultMetrics?: DefaultMetricsCollectorConfiguration<RegistryContentType>;
|
|
113
174
|
/**
|
|
114
175
|
* All metrics in prometheus are global so to prevent clashes in naming
|
|
115
176
|
* we reset the global metrics registry on creation - to not do this,
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2JG;AAIH,OAAO,EAAyB,KAAK,oCAAoC,EAAY,KAAK,QAAQ,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAMjJ,OAAO,KAAK,EAAE,uBAAuB,EAA6D,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAQ5I,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAA;IAEnB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAE/B;;OAEG;IACH,cAAc,CAAC,EAAE,oCAAoC,CAAC,mBAAmB,CAAC,CAAA;IAE1E;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAClC;AAED,MAAM,WAAW,iCAAiC,CAAC,CAAC,GAAC,MAAM,CAAE,SAAQ,uBAAuB,CAAC,CAAC,CAAC;IAC7F,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAoND,wBAAgB,iBAAiB,CAAE,IAAI,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,MAAM,OAAO,CAIvF"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,10 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* @module libp2p-prometheus-metrics
|
|
4
|
+
* Configure your libp2p node with Prometheus metrics:
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* ```js
|
|
7
|
+
* import { createLibp2p } from 'libp2p'
|
|
8
|
+
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
9
|
+
*
|
|
10
|
+
* const node = await createLibp2p({
|
|
11
|
+
* metrics: prometheusMetrics()
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Then use the `prom-client` module to supply metrics to the Prometheus/Graphana client using your http framework:
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import client from 'prom-client'
|
|
19
|
+
*
|
|
20
|
+
* async handler (request, h) {
|
|
21
|
+
* return h.response(await client.register.metrics())
|
|
22
|
+
* .type(client.register.contentType)
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* All Prometheus metrics are global so there's no other work required to extract them.
|
|
27
|
+
*
|
|
28
|
+
* ### Queries
|
|
29
|
+
*
|
|
30
|
+
* Some useful queries are:
|
|
31
|
+
*
|
|
32
|
+
* #### Data sent/received
|
|
33
|
+
*
|
|
34
|
+
* ```
|
|
35
|
+
* rate(libp2p_data_transfer_bytes_total[30s])
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* #### CPU usage
|
|
39
|
+
*
|
|
40
|
+
* ```
|
|
41
|
+
* rate(process_cpu_user_seconds_total[30s]) * 100
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* #### Memory usage
|
|
45
|
+
*
|
|
46
|
+
* ```
|
|
47
|
+
* nodejs_memory_usage_bytes
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* #### DHT query time
|
|
51
|
+
*
|
|
52
|
+
* ```
|
|
53
|
+
* libp2p_kad_dht_wan_query_time_seconds
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* or
|
|
57
|
+
*
|
|
58
|
+
* ```
|
|
59
|
+
* libp2p_kad_dht_lan_query_time_seconds
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* #### TCP transport dialer errors
|
|
63
|
+
*
|
|
64
|
+
* ```
|
|
65
|
+
* rate(libp2p_tcp_dialer_errors_total[30s])
|
|
66
|
+
* ```
|
|
8
67
|
*
|
|
9
68
|
* @example
|
|
10
69
|
*
|
|
@@ -20,10 +79,11 @@
|
|
|
20
79
|
*
|
|
21
80
|
* myMetric.update(1)
|
|
22
81
|
* ```
|
|
23
|
-
* A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped:
|
|
24
82
|
*
|
|
25
83
|
* @example
|
|
26
84
|
*
|
|
85
|
+
* A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped:
|
|
86
|
+
*
|
|
27
87
|
* ```typescript
|
|
28
88
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
29
89
|
*
|
|
@@ -39,10 +99,10 @@
|
|
|
39
99
|
* })
|
|
40
100
|
* ```
|
|
41
101
|
*
|
|
42
|
-
* If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead:
|
|
43
|
-
*
|
|
44
102
|
* @example
|
|
45
103
|
*
|
|
104
|
+
* If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead:
|
|
105
|
+
*
|
|
46
106
|
* ```typescript
|
|
47
107
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
48
108
|
*
|
|
@@ -58,14 +118,14 @@
|
|
|
58
118
|
*
|
|
59
119
|
* There are specific metric groups for tracking libp2p connections and streams:
|
|
60
120
|
*
|
|
61
|
-
* Track a newly opened multiaddr connection:
|
|
62
121
|
* @example
|
|
63
122
|
*
|
|
123
|
+
* Track a newly opened multiaddr connection:
|
|
124
|
+
*
|
|
64
125
|
* ```typescript
|
|
65
126
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
66
127
|
* import { createLibp2p } from 'libp2p'
|
|
67
128
|
*
|
|
68
|
-
*
|
|
69
129
|
* const metrics = prometheusMetrics()()
|
|
70
130
|
*
|
|
71
131
|
* const libp2p = await createLibp2p({
|
|
@@ -76,9 +136,10 @@
|
|
|
76
136
|
* const connections = metrics.trackMultiaddrConnection(connection)
|
|
77
137
|
* ```
|
|
78
138
|
*
|
|
79
|
-
* Track a newly opened stream:
|
|
80
139
|
* @example
|
|
81
140
|
*
|
|
141
|
+
* Track a newly opened stream:
|
|
142
|
+
*
|
|
82
143
|
* ```typescript
|
|
83
144
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
84
145
|
* import { createLibp2p } from 'libp2p'
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2JG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,IAAI,MAAM,YAAY,CAAA;AAC7B,OAAO,EAAE,qBAAqB,EAA6C,QAAQ,EAA2C,MAAM,aAAa,CAAA;AACjJ,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAA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AAI,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/prometheus-metrics",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9-025c082a",
|
|
4
4
|
"description": "Collect libp2p metrics for scraping by Prometheus or Graphana",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "Apache-2.0 OR MIT",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
"test:electron-main": "aegir test -t electron-main --cov"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@libp2p/interface": "
|
|
47
|
-
"@libp2p/logger": "
|
|
46
|
+
"@libp2p/interface": "0.1.4-025c082a",
|
|
47
|
+
"@libp2p/logger": "3.0.4-025c082a",
|
|
48
48
|
"it-foreach": "^2.0.3",
|
|
49
49
|
"it-stream-types": "^2.0.1",
|
|
50
|
-
"prom-client": "^
|
|
50
|
+
"prom-client": "^15.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@libp2p/interface-compliance-tests": "
|
|
54
|
-
"@libp2p/peer-id-factory": "
|
|
53
|
+
"@libp2p/interface-compliance-tests": "4.1.2-025c082a",
|
|
54
|
+
"@libp2p/peer-id-factory": "3.0.6-025c082a",
|
|
55
55
|
"@multiformats/multiaddr": "^12.1.3",
|
|
56
56
|
"aegir": "^41.0.2",
|
|
57
57
|
"it-drain": "^3.0.2",
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* @module libp2p-prometheus-metrics
|
|
4
|
+
* Configure your libp2p node with Prometheus metrics:
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* ```js
|
|
7
|
+
* import { createLibp2p } from 'libp2p'
|
|
8
|
+
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
9
|
+
*
|
|
10
|
+
* const node = await createLibp2p({
|
|
11
|
+
* metrics: prometheusMetrics()
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Then use the `prom-client` module to supply metrics to the Prometheus/Graphana client using your http framework:
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import client from 'prom-client'
|
|
19
|
+
*
|
|
20
|
+
* async handler (request, h) {
|
|
21
|
+
* return h.response(await client.register.metrics())
|
|
22
|
+
* .type(client.register.contentType)
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* All Prometheus metrics are global so there's no other work required to extract them.
|
|
27
|
+
*
|
|
28
|
+
* ### Queries
|
|
29
|
+
*
|
|
30
|
+
* Some useful queries are:
|
|
31
|
+
*
|
|
32
|
+
* #### Data sent/received
|
|
33
|
+
*
|
|
34
|
+
* ```
|
|
35
|
+
* rate(libp2p_data_transfer_bytes_total[30s])
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* #### CPU usage
|
|
39
|
+
*
|
|
40
|
+
* ```
|
|
41
|
+
* rate(process_cpu_user_seconds_total[30s]) * 100
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* #### Memory usage
|
|
45
|
+
*
|
|
46
|
+
* ```
|
|
47
|
+
* nodejs_memory_usage_bytes
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* #### DHT query time
|
|
51
|
+
*
|
|
52
|
+
* ```
|
|
53
|
+
* libp2p_kad_dht_wan_query_time_seconds
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* or
|
|
57
|
+
*
|
|
58
|
+
* ```
|
|
59
|
+
* libp2p_kad_dht_lan_query_time_seconds
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* #### TCP transport dialer errors
|
|
63
|
+
*
|
|
64
|
+
* ```
|
|
65
|
+
* rate(libp2p_tcp_dialer_errors_total[30s])
|
|
66
|
+
* ```
|
|
8
67
|
*
|
|
9
68
|
* @example
|
|
10
69
|
*
|
|
@@ -20,10 +79,11 @@
|
|
|
20
79
|
*
|
|
21
80
|
* myMetric.update(1)
|
|
22
81
|
* ```
|
|
23
|
-
* A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped:
|
|
24
82
|
*
|
|
25
83
|
* @example
|
|
26
84
|
*
|
|
85
|
+
* A metric that is expensive to calculate can be created by passing a `calculate` function that will only be invoked when metrics are being scraped:
|
|
86
|
+
*
|
|
27
87
|
* ```typescript
|
|
28
88
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
29
89
|
*
|
|
@@ -39,10 +99,10 @@
|
|
|
39
99
|
* })
|
|
40
100
|
* ```
|
|
41
101
|
*
|
|
42
|
-
* If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead:
|
|
43
|
-
*
|
|
44
102
|
* @example
|
|
45
103
|
*
|
|
104
|
+
* If several metrics should be grouped together (e.g. for graphing purposes) `registerMetricGroup` can be used instead:
|
|
105
|
+
*
|
|
46
106
|
* ```typescript
|
|
47
107
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
48
108
|
*
|
|
@@ -58,14 +118,14 @@
|
|
|
58
118
|
*
|
|
59
119
|
* There are specific metric groups for tracking libp2p connections and streams:
|
|
60
120
|
*
|
|
61
|
-
* Track a newly opened multiaddr connection:
|
|
62
121
|
* @example
|
|
63
122
|
*
|
|
123
|
+
* Track a newly opened multiaddr connection:
|
|
124
|
+
*
|
|
64
125
|
* ```typescript
|
|
65
126
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
66
127
|
* import { createLibp2p } from 'libp2p'
|
|
67
128
|
*
|
|
68
|
-
*
|
|
69
129
|
* const metrics = prometheusMetrics()()
|
|
70
130
|
*
|
|
71
131
|
* const libp2p = await createLibp2p({
|
|
@@ -76,9 +136,10 @@
|
|
|
76
136
|
* const connections = metrics.trackMultiaddrConnection(connection)
|
|
77
137
|
* ```
|
|
78
138
|
*
|
|
79
|
-
* Track a newly opened stream:
|
|
80
139
|
* @example
|
|
81
140
|
*
|
|
141
|
+
* Track a newly opened stream:
|
|
142
|
+
*
|
|
82
143
|
* ```typescript
|
|
83
144
|
* import { prometheusMetrics } from '@libp2p/prometheus-metrics'
|
|
84
145
|
* import { createLibp2p } from 'libp2p'
|
|
@@ -96,7 +157,7 @@
|
|
|
96
157
|
|
|
97
158
|
import { logger } from '@libp2p/logger'
|
|
98
159
|
import each from 'it-foreach'
|
|
99
|
-
import { collectDefaultMetrics, type DefaultMetricsCollectorConfiguration, register, type Registry } from 'prom-client'
|
|
160
|
+
import { collectDefaultMetrics, type DefaultMetricsCollectorConfiguration, register, type Registry, type RegistryContentType } from 'prom-client'
|
|
100
161
|
import { PrometheusCounterGroup } from './counter-group.js'
|
|
101
162
|
import { PrometheusCounter } from './counter.js'
|
|
102
163
|
import { PrometheusMetricGroup } from './metric-group.js'
|
|
@@ -126,7 +187,7 @@ export interface PrometheusMetricsInit {
|
|
|
126
187
|
/**
|
|
127
188
|
* prom-client options to pass to the `collectDefaultMetrics` function
|
|
128
189
|
*/
|
|
129
|
-
defaultMetrics?: DefaultMetricsCollectorConfiguration
|
|
190
|
+
defaultMetrics?: DefaultMetricsCollectorConfiguration<RegistryContentType>
|
|
130
191
|
|
|
131
192
|
/**
|
|
132
193
|
* All metrics in prometheus are global so to prevent clashes in naming
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"PrometheusCalculatedMetricOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_prometheus_metrics.PrometheusCalculatedMetricOptions.html",
|
|
3
|
-
".:PrometheusCalculatedMetricOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_prometheus_metrics.PrometheusCalculatedMetricOptions.html",
|
|
4
|
-
"PrometheusMetricsInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_prometheus_metrics.PrometheusMetricsInit.html",
|
|
5
|
-
".:PrometheusMetricsInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_prometheus_metrics.PrometheusMetricsInit.html",
|
|
6
|
-
"prometheusMetrics": "https://libp2p.github.io/js-libp2p/functions/_libp2p_prometheus_metrics.prometheusMetrics.html",
|
|
7
|
-
".:prometheusMetrics": "https://libp2p.github.io/js-libp2p/functions/_libp2p_prometheus_metrics.prometheusMetrics.html"
|
|
8
|
-
}
|