@telemetry-js/publisher-cloudwatch

1.0.0 • Public • Published

publisher-cloudwatch

Publish single or summary metrics to AWS CloudWatch.
A telemetry plugin.

npm status node Test JavaScript Style Guide

Table of Contents

Click to expand

Usage

With Telemetry

const telemetry = require('@telemetry-js/telemetry')()
const cloudwatch = require('@telemetry-js/publisher-cloudwatch')

telemetry.task()
  .publish(cloudwatch)

// Or with options
telemetry.task()
  .publish(cloudwatch, { /* options */ })

If an HTTP request to CloudWatch fails, it is retried. If it fails 5 times, an error event will be emitted and in this case forwarded to telemetry:

telemetry.on('error', (err) => {
  console.error(err)
})

Standalone

Useful to publish one-time metrics.

const cloudwatch = require('@telemetry-js/publisher-cloudwatch')
const single = require('@telemetry-js/metric').single

const publisher = cloudwatch()
const metric = single('myapp.example.count', { unit: 'count', value: 10 })

publisher.publish(metric)

await publisher.flush()

The flush method will yield an error if the HTTP request failed (after retries).

To publish multiple metrics (in one HTTP request), repeat the .publish() call before .flush():

const metric1 = single('myapp.example.count', { unit: 'count', value: 10 })
const metric2 = single('myapp.foobar.bytes', { unit: 'bytes', value: 10 })

publisher.publish(metric1)
publisher.publish(metric2)

await publisher.flush()

Options

  • namespace: string, defaults to telemetry
  • retry: boolean, defaults to true
  • retryDelay: number, milliseconds, defaults to 1000
  • timeout: socket timeout, number, milliseconds, defaults to 60 seconds
  • credentials: AWS credentials in the form of { accessKeyId, secretAccessKey }. You normally don't need to set this, as credentials are fetched with awscred which supports EC2, ECS, Lambda, ..
  • region: AWS CloudWatch region. You normally don't need to set this, as it is fetched with awscred.

Install

With npm do:

npm install @telemetry-js/publisher-cloudwatch

Acknowledgements

This project is kindly sponsored by Reason Cybersecurity Ltd.

reason logo

License

MIT © Vincent Weevers

Package Sidebar

Install

npm i @telemetry-js/publisher-cloudwatch

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

24.1 kB

Total Files

7

Last publish

Collaborators

  • vweevers