npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wavefront-lambda

v0.9.1

Published

Wavefront Lambda Wrapper to direcly report metrics from AWS Lambda functions.

Downloads

513

Readme

wavefront-lambda-nodejs

This is a Wavefront Nodejs wrapper for AWS Lambda to enable reporting standard lambda metrics and custom app metrics directly to wavefront.

Requirements

Node.js runtime v8.10

Installation

npm install wavefront-lambda

Environment variables

WAVEFRONT_URL = <INSTANCE>.wavefront.com
WAVEFRONT_API_TOKEN = Wavefront API token with Direct Data Ingestion permission.
REPORT_STANDARD_METRICS = Set to False or false to not report standard lambda metrics directly to wavefront.

Usage

Wrap your AWS Lambda handler function.

const wavefrontLambda = require('wavefront-lambda')
const metrics = require('wavefrontmetrics');

exports.myHandler = wavefrontLambda.wrapper(function(event, context, callback) {
  // your code
});

Standard Lambda Metrics reported by Wavefront Lambda wrapper

The Lambda wrapper sends the following standard lambda metrics to wavefront:

| Metric Name | Type | Description | | ----------------------------------|:------------------:| ----------------------------------------------------------------------- | | aws.lambda.wf.invocations.count | Delta Counter | Count of number of lambda function invocations aggregated at the server.| | aws.lambda.wf.errors.count | Delta Counter | Count of number of errors aggregated at the server. | | aws.lambda.wf.coldstarts.count | Delta Counter | Count of number of cold starts aggregated at the server. | | aws.lambda.wf.duration.value | Gauge | Execution time of the Lambda handler function in milliseconds. |

The Lambda wrapper adds the following point tags to all metrics sent to wavefront:

| Point Tag | Description | | --------------------- | ----------------------------------------------------------------------------- | | LambdaArn | ARN(Amazon Resource Name) of the Lambda function. | | Region | AWS Region of the Lambda function. | | accountId | AWS Account ID from which the Lambda function was invoked. | | ExecutedVersion | The version of Lambda function. | | FunctionName | The name of Lambda function. | | Resource | The name and version/alias of Lambda function. (Ex: DemoLambdaFunc:aliasProd) | | EventSourceMappings | AWS Event source mapping Id. (Set in case of Lambda invocation by AWS Poll-Based Services)|

Custom Lambda Metrics

The wavefront nodejs lambda wrapper reports custom business metrics via API's provided by the [nodejs-metrics-wavefront client] (https://github.com/wavefrontHQ/nodejs-metrics-wavefront).
Please refer to the below code sample which shows how you can send custom business metrics to wavefront from your lambda function.

Code Sample

const wavefrontLambda = require('wavefront-lambda')
const metrics = require('wavefrontmetrics');

exports.myHandler = wavefrontLambda.wrapper(function(event, context, callback) {
  // Get registry to report metrics.
  let registry = wavefrontLambda.getRegistry();

  // Register and report Counters with app tags.
  let counter = new metrics.Counter();
  registry.addTaggedMetric("sample.counter.count", counter, {"key1":"val1"});
  counter.inc();

  // Register and report Delta Counters with app tags.
  let deltaCounter = new metrics.Counter();
  let deltaCounterName = metrics.deltaCounterName("sample.deltaCounter.count");
  registry.addTaggedMetric(deltaCounterName, deltaCounter, {"key1":"val1"});
  deltaCounter.inc();

  callback(null, "some success message");
  // or
  // callback("some error type");
});

Note: Having the same metric name for any two types of metrics will result in only one time series at the server and thus cause collisions. In general, all metric names should be different. In case you have metrics that you want to track as both a Counter and Delta Counter, consider adding a relevant suffix to one of the metrics to differentiate one metric name from another.