@emartech/aggregate-metric-logger 2.0.0 → 2.0.3
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 +15 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ aggregate metrics in memory and log them every minute
|
|
|
4
4
|
## Setup
|
|
5
5
|
|
|
6
6
|
Set `METRIC_LOGGER_ENABLED` env variable to `true` for aggregate-metric-logger to
|
|
7
|
-
start collecting and logging
|
|
7
|
+
start collecting and logging measurements.
|
|
8
8
|
|
|
9
9
|
To change the default `aggregate-metric-logger` namespace used for logs, set
|
|
10
10
|
`METRIC_LOGGER_NAMESPACE` to a custom value.
|
|
@@ -19,7 +19,7 @@ an extra `count` property to the logs and log them at the end of the minute with
|
|
|
19
19
|
`@emartech/json-logger`.
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
const
|
|
22
|
+
const metricLogger = require('@emartech/aggregate-metric-logger')
|
|
23
23
|
|
|
24
24
|
metricLogger.warn('etwas-went-wrong', { customer_id: 11 });
|
|
25
25
|
metricLogger.warn('etwas-went-wrong', { customer_id: 11 });
|
|
@@ -29,11 +29,11 @@ metricLogger.warn('etwas-went-wrong', { customer_id: 11 });
|
|
|
29
29
|
|
|
30
30
|
### Measure values
|
|
31
31
|
|
|
32
|
-
If you want aggregate
|
|
32
|
+
If you want aggregate measurements about something you need to simply call the `measure` method
|
|
33
33
|
for each value:
|
|
34
34
|
|
|
35
35
|
```js
|
|
36
|
-
const
|
|
36
|
+
const metricLogger = require('@emartech/aggregate-metric-logger')
|
|
37
37
|
|
|
38
38
|
metricLogger.measure('thing-to-measure', 14)
|
|
39
39
|
metricLogger.measure('thing-to-measure', 20)
|
|
@@ -44,16 +44,16 @@ for each measured tags. (Uses `@emartech/json-logger` behind the scenes for logg
|
|
|
44
44
|
|
|
45
45
|
### Measuring durations
|
|
46
46
|
|
|
47
|
-
For duration
|
|
47
|
+
For duration measurements, there are two convenient methods: `start`, and `stop`;
|
|
48
48
|
|
|
49
49
|
You start the measurement with `start`, the counted value for aggregation will be the duration
|
|
50
|
-
between this `start` and the
|
|
50
|
+
between this `start` and the matching `stop` call;
|
|
51
51
|
|
|
52
52
|
```js
|
|
53
53
|
function exampleIOHeavyFunction() {
|
|
54
|
-
const
|
|
54
|
+
const measurement = metricLogger.start('tag-for-the-measuement');
|
|
55
55
|
const result = db.findItems();
|
|
56
|
-
metricLogger.stop(
|
|
56
|
+
metricLogger.stop(measurement);
|
|
57
57
|
return result;
|
|
58
58
|
}
|
|
59
59
|
```
|
|
@@ -61,20 +61,20 @@ function exampleIOHeavyFunction() {
|
|
|
61
61
|
### Group by extra parameters
|
|
62
62
|
|
|
63
63
|
If you want to group by additional parameters inside a tag, you can pass down these extra
|
|
64
|
-
params in an object to `
|
|
64
|
+
params in an object to `measure` and `start` as the last optional argument:
|
|
65
65
|
|
|
66
66
|
```js
|
|
67
|
-
metricLogger.
|
|
67
|
+
metricLogger.measure('thing-to-count', 14, { customer_id: 12 });
|
|
68
68
|
|
|
69
|
-
const
|
|
69
|
+
const measurement = metricLogger.start(
|
|
70
70
|
'tag-for-the-measuement',
|
|
71
71
|
{ event_type: 'nyul', account: 3 }
|
|
72
72
|
);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
A
|
|
76
|
-
and these extra params will appended to the log entry.
|
|
75
|
+
A separate log entry will be created for each seen value combinations seen in the extra params
|
|
76
|
+
and these extra params will be appended to the log entry.
|
|
77
77
|
|
|
78
|
-
Be very
|
|
79
|
-
If you include too many parameters, you could
|
|
78
|
+
Be very careful when using extra params, and only include information you really need.
|
|
79
|
+
If you include too many parameters, you could lose the advantage you gain by aggregating your logs
|
|
80
80
|
with this package.
|