6.0.2 • Published 5 months ago

@emartech/aggregate-metric-logger v6.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

aggregate-metric-logger

Aggregate metrics in memory and send them to GCP them every minute.

Setup

Set METRIC_LOGGER_ENABLED env variable to true for aggregate-metric-logger to start collecting and logging measurements.

Set MONITORING_PROJECT_ID and GCP_CREDENTIALS env variables. HOSTNAME env variable also has to be set, but for a pod running on kubernetes this should already be set.

Add Monitoring Metrics Writer Role to the service account in the GCP project.

Usage

Count occurrences

const metricLogger = require('@emartech/aggregate-metric-logger')

metricLogger.count('etwas-went-wrong', { customer_id: 11 });
metricLogger.count('etwas-went-wrong', { customer_id: 11 });

// will aggregate these to a single metric

Measure values

If you want aggregate measurements about something you need to simply call the measure method for each value:

const metricLogger = require('@emartech/aggregate-metric-logger')

metricLogger.measure('thing-to-measure', 14, { customer_id: 12 })
metricLogger.measure('thing-to-measure', 20, { customer_id: 44 })

Measuring durations

For duration measurements, there are two convenient methods: start, and stop;

You start the measurement with start, the counted value for aggregation will be the duration between this start and the matching stop call;

function exampleIOHeavyFunction() {
  const measurement = metricLogger.start('tag-for-the-measuement', { customer_id: 23 });
  const result = db.findItems();
  metricLogger.stop(measurement);
  return result;
}
5.2.1

1 year ago

5.2.0

1 year ago

5.0.2

1 year ago

5.1.0

1 year ago

5.0.1

1 year ago

6.0.1

5 months ago

6.0.0

5 months ago

6.0.2

5 months ago

5.0.0

2 years ago

3.3.2

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.3.1

3 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.1.2

3 years ago

2.2.0

3 years ago

2.1.1

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.0

3 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago