{"id":24559255,"url":"https://github.com/parcellab/aws-loop-timer","last_synced_at":"2025-07-06T21:02:41.808Z","repository":{"id":10008705,"uuid":"64075212","full_name":"parcelLab/aws-loop-timer","owner":"parcelLab","description":"Logging Node.js loop times to CloudWatch.","archived":false,"fork":false,"pushed_at":"2022-11-22T21:03:44.000Z","size":6,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-02-23T22:06:43.533Z","etag":null,"topics":["team-architecture"],"latest_commit_sha":null,"homepage":"https://parcellab.com/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parcelLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-24T16:38:42.000Z","updated_at":"2025-02-21T21:39:49.000Z","dependencies_parsed_at":"2023-01-13T15:41:24.714Z","dependency_job_id":null,"html_url":"https://github.com/parcelLab/aws-loop-timer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parcelLab%2Faws-loop-timer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parcelLab%2Faws-loop-timer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parcelLab%2Faws-loop-timer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parcelLab%2Faws-loop-timer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parcelLab","download_url":"https://codeload.github.com/parcelLab/aws-loop-timer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243922338,"owners_count":20369382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["team-architecture"],"created_at":"2025-01-23T06:16:03.378Z","updated_at":"2025-03-16T19:41:42.977Z","avatar_url":"https://github.com/parcelLab.png","language":"JavaScript","readme":"\u003e Logging Node.js loop times to CloudWatch.\n\nTable of Contents: [What does this package do?](#what-does-this-package-do), [How to use?](#how-to-use), [Debugging](#debugging), [Notes on AWS CloudWatch](#notes-on-aws-cloudwatch), [Contribution](#contribution)\n\n\n# What does this package do?\n\nThe *aws-loop-timer* measures loop times (or cycle times) within your [Node.js](https://nodejs.org) applications and logs them using [AWS CloudWatch](https://aws.amazon.com/cloudwatch). With CloudWatch, you can easily monitor those metrics with alarms, dashboards etc.\n\n# How to use?\n\n## Install\n\nLike always:\n\n```\nnpm i aws-loop-timer --save\n```\n\n## Require\n\nWhen requiring you need to provide your AWS credentials and region, and you also define the `namespace`:\n\n```\nvar namespace = 'my-namespace'; // this can be any string and probably should be unique per project\n\nvar Timer = require('aws-loop-timer')('eu-central-1', 'AWS-KEY', 'AWS-SECRET', namespace);\n```\n\nJust 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.\n\n## Init\n\nFirst, you need to spin up a timer. When doing so, you can assign the timer a `name`, and a `pulse`.\n\n**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.\n\n**pulse** (optional): 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.\n\n**You probably should set a pulse, because CloudWatch only allows 150 uploads per second!** For more info on that topic, read below.\n\n**silent** (optional): As per default, the timer writes its results also to the default output. If you want to override this behavior, you can set it to `silent` using any truthy value, e.g. `true` or `'silent'`, latter being a bit more explicit.\n\n```\nvar name = 'name-of-the-timer'; // this will be your metric's name\nvar pulse = 5; // this means data will be pushed to CloudWatch every five seconds\n\nvar timer = Timer.getTimer(name, pulse); // this will write results to the console\nvar silentTimer = Timer.getTimer('i-am-silent', 0, 'silent'); // this one will not\n```\n\n## Measure\n\nFinally we can measure loop times! This is now fairly simple with the object `timer` we created above.\n\n1. Start the timer: `timer.start();`\n1. End it: `timer.end();`\n\nThat's it.\n\n# Debugging\n\nNote 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.\n\n# Notes on AWS CloudWatch\n\nSome additional notes on the `pulse` setting. You have to know that [AWS CloudWatch only allows to upload 150 times per second](http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_limits.html). There are two ways to mitigate this if you're in danger of exceeding this limit:\n\n1. Upload several metrics at once. This package currently does not do that (would be a good [contribution](#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.\n1. Alternatively, and this is done here, you can already calculate an average of the loop times and only push this one.\n\n# Contribution\n\nPlease do.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparcellab%2Faws-loop-timer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparcellab%2Faws-loop-timer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparcellab%2Faws-loop-timer/lists"}