1.0.2 • Published 4 years ago

@sharethrough/nestjs-signalfx v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Description

SignalFx module for Nest.

Installation

$ npm i --save @sharethrough/nestjs-signalfx signalfx

Quick Start

Importing the module

Import the module like so

import { Module }         from '@nestjs/common'
import { SignalfxModule, SignalfxOptions } from '@sharethrough/nestjs-signalfx';

@Module({
  imports: [
    SignalfxModule.forRoot(options: SignalfxOptions)
  ],
})

where options is an object which satisfies the SignalfxOptions interface

interface SignalfxOptions {
  // name for your signalfx connection, so it doesn't clash with other modules
  namespace: string; 
  // access token for connection to signalfx
  accessToken: string; 
  // your ingest endpoint for signalfx, e.g. https://ingest.us1.signalfx.com 
  ingestEndpoint: string; 
  // optional: default dimensions to add to all metrics you push
  dimensions?: { [x: string]: string }; 
}

You can then inject the SignalfxService with the provided decorator

@InjectSignalfx(namespace) private readonly signalfxService: SignalfxService

where namespace is the name you used in your options.

Sending metrics

Once you have injected the service, you can add gauges, counters, and cumulative counters to the buffer via their respective methods:

signalfxService.gauge(args)
signalfxService.counter(args)
signalfxService.cumulativeCounter(args)

Each method takes the same 4 positional arguments

// required: the name of the metric
metric: string
// required: the value to send
value: number
// optional: the timestamp. If not provided, defaults to `Date.now()`
timestamp: number = Date.now()
// optional: dimensions to apply for this metric. Will be applied on top of default dimensions if specified.
dimensions: { [x: string]: string } = null

Each method will add the metric to a buffer. To send all metrics stored in the buffer you can use the send() method:

signalfxService.send();

License

Nest is MIT licensed.

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago