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

aws-loop-timer

v0.0.1

Published

Logging Node.js loop times to CloudWatch

Downloads

9

Readme

Logging Node.js loop times to CloudWatch.

Table of Contents: What does this package do?, How to use?, Debugging, Notes on AWS CloudWatch, Contribution

What does this package do?

The aws-loop-timer measures loop times (or cycle times) within your Node.js applications and logs them using AWS CloudWatch. With CloudWatch, you can easily monitor those metrics with alarms, dashboards etc.

How to use?

Install

Like always:

npm i aws-loop-timer --save

Require

When requiring you need to provide your AWS credentials and region, and you also define the namespace:

var namespace = 'my-namespace'; // this can be any string and probably should be unique per project

var Timer = require('aws-loop-timer')('eu-central-1', 'AWS-KEY', 'AWS-SECRET', namespace);

Just to be clear: my-namespace can be any string you deem okay, and your AWS credentials need be authorized to access the CloudWatch region your trying to write to.

Init

First, you need to spin up a timer. When doing so, you can assign the timer a name, and a pulse.

name: Okay, so the name will also be the name of the metric on CloudWatch. This means, this should be unique for every loop you want to measure. Whereas the namespace when requiring the module could be the same throughout the project.

pulse: The pulse is the number of seconds how often your timer pushed data to CloudWatch. E.g. if you set it to 5, loop times will be averaged over five seconds and this average will be uploaded only. If you don't set a pulse, i.e. set it to 0, each loop time will be uploaded immediately.

You probably should set a pulse, because CloudWatch only allows 150 uploads per second! For more info on that topic, read below.

var name = 'name-of-the-timer'; // this will be your metric's name
var pulse = 5; // this means data will be pushed to CloudWatch every five seconds

var timer = Timer.getTimer(name, pulse);

Measure

Finally we can measure loop times! This is now fairly simple with the object timer we created above.

  1. Start the timer: timer.start();
  2. End it: timer.end();

That's it.

Debugging

Note that this package never throws an error, it only logs error to the console. This is because this logger should not break your application logic.

Notes on AWS CloudWatch

Some additional notes on the pulse setting. You have to know that AWS CloudWatch only allows to upload 150 times per second. There are two ways to mitigate this if you're in danger of exceeding this limit:

  1. Upload several metrics at once. This package currently does not do that (would be a good contribution), it only uploads one loop time per request to CloudWatch. One could theoretically piggy-ride on the existing pulse to store all loop times in memory and upload an array of all measurements with a single request. Then it's only important to respect the 40 KB POST data limit on uploads.
  2. Alternatively, and this is done here, you can already calculate an average of the loop times and only push this one.

Contribution

Please do.