JSPM

@telemetry-js/publisher-cloudwatch

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q11877F
  • License MIT

Publish single or summary metrics to AWS CloudWatch

Package Exports

  • @telemetry-js/publisher-cloudwatch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@telemetry-js/publisher-cloudwatch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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