{"id":24678315,"url":"https://github.com/firstclasspostcodes/metrics","last_synced_at":"2025-09-11T12:39:22.661Z","repository":{"id":54416868,"uuid":"267290571","full_name":"firstclasspostcodes/metrics","owner":"firstclasspostcodes","description":"👓 Easily publish custom AWS CloudWatch Metrics","archived":false,"fork":false,"pushed_at":"2021-02-19T07:21:32.000Z","size":3457,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T22:56:29.200Z","etag":null,"topics":["aws","cloudwatch","lambda","nodejs","serverless"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firstclasspostcodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-27T10:34:39.000Z","updated_at":"2021-02-19T07:21:34.000Z","dependencies_parsed_at":"2022-08-13T15:00:49.991Z","dependency_job_id":null,"html_url":"https://github.com/firstclasspostcodes/metrics","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstclasspostcodes%2Fmetrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstclasspostcodes%2Fmetrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstclasspostcodes%2Fmetrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstclasspostcodes%2Fmetrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstclasspostcodes","download_url":"https://codeload.github.com/firstclasspostcodes/metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244845403,"owners_count":20519954,"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":["aws","cloudwatch","lambda","nodejs","serverless"],"created_at":"2025-01-26T13:16:38.037Z","updated_at":"2025-03-21T18:23:32.322Z","avatar_url":"https://github.com/firstclasspostcodes.png","language":"JavaScript","readme":"# Metrics\n\nWe use this library internally to easily integrate AWS CloudWatch Custom Metrics into our applications.\n\nTo get started:\n\n```sh\nnpm i @firstclasspostcodes/metrics -s\n```\n\nNow, add a configuration file named `metrics.config.js` to the working directory. This library uses [cosmiconfig](https://www.npmjs.com/package/cosmiconfig) so name your file accordingly.\n\n```js\nmodule.exports = {\n  // Required: this is the namespace that all custom metrics will be published with\n  namespace: 'Test/Service',\n  // Required: the AWS region that the metrics will be published to\n  region: process.env.AWS_REGION,\n  // Optional: for serverless functions, specify `manualMode` to ensure that a metric\n  // flush interval is not started.\n  manualMode: true,\n  // Required: define the custom metrics available to the application at runtime.\n  metrics: {\n    // this is the key that a custom metric will be configured as\n    interestingMetric: {\n      // Optional: a list of dimensions for the metric\n      dimensions: [\n        {\n          Name: 'Function',\n          Value: 'normalHandler',\n        },\n      ],\n      // Optional: define the resolution for the metric, 1-60. Defaults to 60.\n      resolution: 1,\n      // Required: the type of metric being recorded\n      unit: 'Count/Second',\n    },\n    longRunningFunction: {\n      dimensions: [\n        {\n          Name: 'Function',\n          Value: 'testHandler',\n        },\n      ],\n      resolution: 1,\n      // For measured functions, use milliseconds\n      unit: 'Milliseconds',\n    },\n  },\n};\n```\n\nFor any deployed AWS applications, the correct IAM permissions must be configured:\n\n```yaml\nFunction:\n  Type: 'AWS::Serverless::Function'\n  Properties:\n    # ...\n    Policies:\n      - CloudWatchPutMetricPolicy: {}\n```\n\nor defined explicitly:\n\n```yaml\nStatement:\n  - Effect: Allow\n    Action:\n      - cloudwatch:PutMetricData\n    Resource:\n      - '*'\n```\n\nGiven the configuration above, you can use the configured metrics in the following way:\n\n```js\nconst metrics = require('@firstclasspostcodes/metrics');\n\nconst { longRunningFunc } = require('./example');\n\nexports.handler = async (event) =\u003e {\n  metrics.interestingMetric(event.someValue.length);\n\n  // record the same metric with a custom dimension\n  metrics.interestingMetric(event.someValue.length, [{\n    countryName: 'United States',\n  }])\n\n  const data = await metrics.longRunningFunction(() =\u003e {\n    // this will measure how long it takes to execute using perf_tools\n    return longRunningFunc(event.someValue);\n  }));\n\n  // will log a warning to the console and ignore this\n  metrics.doesNotExistMetric();\n\n  // for lambda functions, make sure to flush metrics\n  // before execution ends\n  await metrics.flush();\n\n  return data;\n};\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstclasspostcodes%2Fmetrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstclasspostcodes%2Fmetrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstclasspostcodes%2Fmetrics/lists"}