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

@janiscommerce/embedded-metrics

v1.0.1

Published

A wrapper to make it easier to use AWS Cloudwatch Embedded Metric Format (EMF)

Downloads

674

Readme

embedded-metrics

Build Status Coverage Status npm version

A wrapper to make it easier to use AWS Cloudwatch Embedded Metric Format (EMF)

Installation

npm install @janiscommerce/embedded-metrics

Usage

const { generateMetric } = require('@janiscommerce/embedded-metrics');

// It is recommended to create the metric generators on their own files and import them when needed
const metricGenerator = generateMetric({
	Namespace: 'JanisCommerce/Something/Prod',
	Dimensions: [
		['clientCode']
	],
	Metrics: ['Success', 'Failure']
});

// clientCode = some-client
// Success = 10
// Failure = 20
// See Positional arguments below to understand generator arguments better
metricGenerator('some-client', 10, 20);

// Call this as many time as you want to register more metric with diferent Dimension value or different Data point values
metricGenerator('other-client', 15, 1);

Defaults

  • Metrics Unit will be set to Count.
  • Metrics StorageResolution will be set to 60 (Standard-resolution metric)

Positional arguments

When creating a metric generator, it will accept as many arguments as needed based on the Metric Directive(s). The directives will be resolved in the following order:

  1. For each Metric Directive: a. For each Dimension: Dimension name will be added as argument b. For each Metric: Metric Name will be added as argument

Note: If the same field is used multiple times, it will be added only once as argument.

Examples

const { generateMetric } = require('@janiscommerce/embedded-metrics');

// Multiple Metric Directives with repeated fields
const metricGenerator = generateMetric([
	{
		Namespace: 'JanisCommerce/Something/Prod',
		Dimensions: [
			['clientCode'] // <- args[0]
		],
		Metrics: ['Success', 'Failure'] // <- args[1] and args[2]
	},
	{
		Namespace: 'JanisCommerce/SomethingElse/Prod',
		Dimensions: [
			['clientCode'] // <- args[0] (already set)
		],
		Metrics: ['Failure', 'Warning', 'Success'] // <- args[1] (already set), args[3] and args[2] (already set)
	}
]);

// clientCode = some-client
// Success = 10
// Failure = 20
// Warning = 20
metricGenerator('some-client', 10, 20, 30);
```json
{
	"_aws": {
		"CloudWatchMetrics": [
			{
				"Namespace": "JanisCommerce/Something/Prod",
				"Dimensions": [
					[
						"clientCode"
					]
				],
				"Metrics": [
					{
						"Unit": "Count",
						"Name": "Success"
					},
					{
						"Unit": "Count",
						"Name": "Failure"
					}
				]
			},
			{
				"Namespace": "JanisCommerce/SomethingElse/Prod",
				"Dimensions": [
					[
						"clientCode"
					]
				],
				"Metrics": [
					{
						"Unit": "Count",
						"Name": "Failure"
					},
					{
						"Unit": "Count",
						"Name": "Warning"
					},
					{
						"Unit": "Count",
						"Name": "Success"
					}
				]
			}
		],
		"Timestamp": 1676499226877
	},
	"clientCode": "some-client",
	"Success": 10,
	"Failure": 20,
	"Warning": 30
}
```