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.
Atelemetryplugin.
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 totelemetryretry: boolean, defaults to trueretryDelay: number, milliseconds, defaults to 1000timeout: socket timeout, number, milliseconds, defaults to 60 secondscredentials: AWS credentials in the form of{ accessKeyId, secretAccessKey }. You normally don't need to set this, as credentials are fetched withawscredwhich supports EC2, ECS, Lambda, ..region: AWS CloudWatch region. You normally don't need to set this, as it is fetched withawscred.
Install
With npm do:
npm install @telemetry-js/publisher-cloudwatchAcknowledgements
This project is kindly sponsored by Reason Cybersecurity Ltd.
License
MIT © Vincent Weevers
