Skip to content

Commit c0bb62e

Browse files
codeflyerSimone Sanfratello
andauthored
Feat/prom client (#9)
* feat: update telemetry library * docs: add new telemetry docs * feat: rename grouped with label * Update README.md Co-authored-by: Simone Sanfratello <[email protected]> Co-authored-by: Simone Sanfratello <[email protected]>
1 parent bcdb5af commit c0bb62e

File tree

7 files changed

+346
-385
lines changed

7 files changed

+346
-385
lines changed

README.md

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,52 +37,70 @@ const configFile = path.join(dirname(import.meta.url), '../metrics.yml')
3737
const telemetry = new Telemetry({ configFile })
3838
telemetry.increaseCount('bitswap-total-connections', 2)
3939

40-
const result = telemetry.export()
40+
const result = await telemetry.export()
4141
console.log(result)
42+
telemetry.resetCount()
4243
```
4344

4445
#### Telemetry instance methods
45-
* clear: Clear the metrics
46-
* createMetric(category, description, metric, type): Create a new metric
47-
* category: String - The given name of the category
48-
* description: String - The category description
49-
* metric: METRIC_COUNT | METRIC_DURATIONS | METRIC_GROUPED_COUNT - The metric defined
50-
* type: null | TYPE_GAUGE - The type of the metric. If not passed the value is defined based on the `metric` attribute.
5146
* export: Export the metrics in `prometheus` format
5247
```
53-
# HELP counter_grouped_count_total COUNTER (grouped-count)
54-
# TYPE counter_grouped_count_total counter
55-
counter_grouped_count_total{id="123"} 1 now
56-
counter_grouped_count_total{id="456"} 2 now
48+
# HELP counter_label_count_total COUNTER (label-count)
49+
# TYPE counter_label_count_total counter
50+
counter_label_count_total{id="123"} 1 now
51+
counter_label_count_total{id="456"} 2 now
5752
```
53+
* resetAll(): Reset all metrics
54+
* resetCounters(): Reset count and labelCount metrics
55+
* async export(): Export values in Prometheus format
5856
* increaseCount(category, amount = 1): Increase the count for a category
5957
* category: String - The given name of the category
58+
* increaseLabelCount(category, labels: Array, amount = 1): Increase the count for a key in a category
59+
* category: String - The given name of the category
60+
* labels: Array<String> - The labels of the metric (eg. ['GET', 404])
6061
* amount: Number (Default 1) - The amount to add to the metric
61-
* decreaseCount(category, amount = 1): Decrease the count for a category
62+
* increaseGauge(category, amount = 1): Increase the gauge for a category
6263
* category: String - The given name of the category
63-
* amount: Number (Default 1) - The amount to remove from the metric
64-
* increaseCountWithKey(category, key, amount = 1): Increase the count for a key in a category
64+
* amount: Number (Default 1) - The amount to add to the metric
65+
* decreaseGauge(category, amount = 1): Increase the gauge for a category
6566
* category: String - The given name of the category
66-
* key: String - The key of the metric
6767
* amount: Number (Default 1) - The amount to add to the metric
68-
* decreaseCountWithKey(category, key, amount = 1): Decrease the count for a key in a category
68+
* setGauge(category, value): Set the gauge for a category
6969
* category: String - The given name of the category
70-
* key: String - The key of the metric
71-
* amount: Number (Default 1) - The amount to remove from the metric
70+
* value: Number - The value to set the metric
7271
* trackDuration(category, promise): Track the duration of an async call
7372
* category: String - The given name of the category
7473
* promise: Promise - The function to be tracked
7574
76-
#### Metrics and types constants
75+
#### Configuration
7776
78-
The constants below are exported
79-
80-
* METRIC_COUNT
81-
* METRIC_DURATIONS
82-
* METRIC_GROUPED_COUNT
83-
* TYPE_COUNTER
84-
* TYPE_HISTOGRAM
85-
* TYPE_GAUGE
77+
Eg. of `metrics.yml`
78+
```yaml
79+
---
80+
component: bitswap-peer
81+
metrics:
82+
count:
83+
s3-request-count:
84+
description: AWS S3 requests
85+
dynamo-request-count:
86+
description: AWS DynamoDB requests
87+
labelCount:
88+
bitswap-request-per-connections-label-count:
89+
description: BitSwap Request Per Connnection
90+
labels:
91+
- method
92+
- status
93+
durations:
94+
bitswap-connections-duration-durations:
95+
description: BitSwap Connnection Duration
96+
gauge:
97+
bitswap-event-loop-utilization:
98+
description: BitSwap Event Loop Utilization
99+
bitswap-total-connections:
100+
description: BitSwap Total Connections
101+
version: 0.1.0
102+
buildDate: "20220307.1423"
103+
```
86104

87105
### Utils
88106
#### dirname

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "e-ipfs-core-lib",
3-
"version": "0.3.0",
3+
"version": "0.4.0-beta-01",
44
"description": "E-IPFS core library",
55
"license": "(Apache-2.0 AND MIT)",
66
"homepage": "https://github.com/elastic-ipfs/core-lib",
@@ -17,12 +17,12 @@
1717
"dependencies": {
1818
"@aws-sdk/util-dynamodb": "^3.218.0",
1919
"bl": "^6.0.0",
20-
"hdr-histogram-js": "^3.0.0",
2120
"js-yaml": "^4.1.0",
2221
"libp2p": "^0.40.0",
2322
"pino": "^8.7.0",
2423
"pino-pretty": "^9.1.1",
2524
"piscina": "^3.2.0",
25+
"prom-client": "^14.1.0",
2626
"protobufjs": "^7.1.2",
2727
"sodium-native": "^3.4.1",
2828
"undici": "^5.13.0",

0 commit comments

Comments
 (0)