@@ -37,52 +37,70 @@ const configFile = path.join(dirname(import.meta.url), '../metrics.yml')
37
37
const telemetry = new Telemetry({ configFile })
38
38
telemetry.increaseCount('bitswap-total-connections', 2)
39
39
40
- const result = telemetry.export()
40
+ const result = await telemetry.export()
41
41
console.log(result)
42
+ telemetry.resetCount()
42
43
```
43
44
44
45
#### 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.
51
46
* export: Export the metrics in ` prometheus ` format
52
47
```
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
57
52
```
53
+ * resetAll(): Reset all metrics
54
+ * resetCounters(): Reset count and labelCount metrics
55
+ * async export(): Export values in Prometheus format
58
56
* increaseCount(category, amount = 1): Increase the count for a category
59
57
* 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])
60
61
* 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
62
63
* 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
65
66
* category: String - The given name of the category
66
- * key: String - The key of the metric
67
67
* 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
69
69
* 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
72
71
* trackDuration(category, promise): Track the duration of an async call
73
72
* category: String - The given name of the category
74
73
* promise: Promise - The function to be tracked
75
74
76
- #### Metrics and types constants
75
+ #### Configuration
77
76
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
+ ```
86
104
87
105
### Utils
88
106
#### dirname
0 commit comments