{"id":15345443,"url":"https://github.com/jthomas/openwhisk-metrics","last_synced_at":"2025-04-15T03:30:56.244Z","repository":{"id":140706016,"uuid":"114995068","full_name":"jthomas/openwhisk-metrics","owner":"jthomas","description":"Node.js library to collect serverless application metrics from OpenWhisk actions","archived":false,"fork":false,"pushed_at":"2018-06-12T11:02:08.000Z","size":54,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-03-24T14:47:08.316Z","etag":null,"topics":["apacheopenwhisk","metrics","monitoring","nodejs","openwhisk","serverless"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jthomas.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-21T10:46:01.000Z","updated_at":"2021-10-31T02:57:28.000Z","dependencies_parsed_at":"2023-07-11T14:35:01.760Z","dependency_job_id":null,"html_url":"https://github.com/jthomas/openwhisk-metrics","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jthomas%2Fopenwhisk-metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jthomas%2Fopenwhisk-metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jthomas%2Fopenwhisk-metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jthomas%2Fopenwhisk-metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jthomas","download_url":"https://codeload.github.com/jthomas/openwhisk-metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249001325,"owners_count":21196348,"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":["apacheopenwhisk","metrics","monitoring","nodejs","openwhisk","serverless"],"created_at":"2024-10-01T11:13:24.885Z","updated_at":"2025-04-15T03:30:56.212Z","avatar_url":"https://github.com/jthomas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openwhisk-metrics\n\nNode.js library to collect serverless application metrics from [OpenWhisk actions](https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md).\n\nServerless functions are wrapped with a proxy to automate recording metrics during invocations.\n\nMetric values for `cpu`, `memory`, `time`, `error` and `cold start` collected by default. Supports adding custom metric values.\n\n## usage\n\nWrap action handlers with the metrics library.\n\n```javascript\nconst metrics = require('openwhisk-metrics')\n\nconst main = params =\u003e {\n  return { message: \"Hello World\" }\n}\n\nmodule.exports.main = metrics(main) \n```\n\nMetrics values are logged to stdout for each invocation of the serverless function.\n\n```\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.memory.rss 53018624 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.memory.heapTotal 34463744 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.memory.heapUsed 16955224 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.memory.external 987361 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.error 0 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.coldstart 0 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.cpu.user 177 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.cpu.system 2 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.time.start 1511605588388 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.time.end 1511605588468 1512489781\nMETRIC \u003cworkspace\u003e.\u003caction_name\u003e.\u003cactivation\u003e.time.duration 80 1512489781\n```\n\nSee [\"Forwarding Metrics\"](#forwarding-metrics) for options on sending metric values to external monitoring services.\n\n## installation\n\n```\n$ npm install openwhisk-metrics\n```\n\n## configuration\n\n### metrics\n\nThe library will execute the metric collection handlers registered in `metrics.collect`.\n\nThe default metric handlers configured to run are `cpu`, `memory`, `time`, `error` and `cold start`.\n\n#### cpu\n\nReturns the values of `process.cpuUsage()` for the function execution duration. This can be used to calculate cpu usage during function execution based upon duration. See [Node.js documentation](https://nodejs.org/api/process.html#process_process_cpuusage_previousvalue) for meaning of these values.\n\n```json\n{\n  \"user\": \u003cmicroseconds\u003e,\n  \"system\": \u003cmicroseconds\u003e\n}\n```\n\n#### memory\n\nReturns the values for `process.memoryUsage` when the wrapped function finishes. See [Node.js documentation](https://nodejs.org/api/process.html#process_process_memoryusage) for meaning of these values.\n\n```json\n{\n  \"rss\": \u003cbytes\u003e,\n  \"heapTotal\": \u003cbytes\u003e,\n  \"heapUsed\": \u003cbytes\u003e,\n  \"external\": \u003cbytes\u003e\n}\n```\n\n#### time\n\nReturns start, end and duration times for function execution. `start` and `end` are in milliseconds since epoch. Duration is the difference between `end` and `start` in milliseconds.\n\n```json\n{\n  \"start\": \u003cmillseconds_since_epoch\u003e,\n  \"end\": \u003cmillseconds_since_epoch\u003e,\n  \"duration\": \u003cmilliseconds_since_start\u003e\n}\n```\n\n#### error\n\nReturns whether wrapped function returns an error. Handles errors returned directly or using rejected Promises. If error was returned, metric value is `0`. If error was not returned, metric value is `1`.\n\n```json\n{\n  \"error\": 0 or 1\n}\n```\n\n#### cold start\n\nReturns whether a new runtime environment is used for execution.  This is used to record cold and warm invocations.\n\nThe first time a new runtime environment is used, `coldstart` will be `1`. All further invocations using an existing environment return `0`.\n\n```json\n{\n  \"coldstart\": 0 or 1\n}\n```\n\n### disable default metrics\n\nMetrics can be disabled by removing the metric handler from `metrics.collect`.\n\n```javascript\n// disable cpu metric\nmetrics.collect.cpu = null\n```\n\n### disable activationId in metrics\n\nOpenwhisk activationId can be disable by setting `metrics.config.ignore_activation_ids` to `true`\n\n```javascript\n// disable activationid in metrics\nmetrics.config.ignore_activation_ids = true\n```\n\n## add custom metrics\n\nSet additional properties on the `metrics.collect` object to collect custom metrics.\n\n```javascript\nmetrics.collect.custom = action_response =\u003e {\n  return 12345\n}\n```\n\nProperty names on the `metrics.collect` object are used as metric labels, e.g. `custom`. Return values from the functions are used as metric values.\n\n**Metric values must be a number. Strings, booleans and other types are not supported.** \n\nMetric functions can either return a raw metric value or multiple sub-properties.\n\n```javascript\n// single value....\nmetrics.collect.custom = action_response =\u003e {\n  return 12345\n}\n// multiple values\nmetrics.collect.custom = action_response =\u003e {\n  return {inner: 12345, ...}\n}\n```\n\nMetric functions are called once the wrapped function has returned, with the return value of that invocation.\n\nIf you need to capture execution context prior to the invocation, set a metric handler using an object with `start` and `end` methods.\n\n```javascript\n// let's record start time for invocations...\nlet start\n\nmetrics.collect.start_times = {\n  start: evt_params =\u003e {\n    start = (new Date()).getTime()\n  },\n  end: fn_return_val =\u003e start\n}\n```\n\n`start` will be executed with invocation parameters prior to the wrapped handler being called. `end` will be executed with return value from wrapped function after invocation.\n\n## forwarding metrics\n\n### background action\n\nMetric values collected during execution are logged to stdout in the following format.\n\n```\nMETRIC \u003cmetric.label.name\u003e \u003cvalue\u003e \u003ctimestamp\u003e \n```\n\nUsing the [alarm trigger feed](https://github.com/apache/incubator-openwhisk-package-alarms), an action can run on a [periodic schedule](https://github.com/apache/incubator-openwhisk-package-alarms#firing-a-trigger-event-periodically-on-an-interval-based-schedule) to retrieve metrics from actions logs. This action can forward metric values to external monitoring services.\n\n### custom agent\n\nCustom agents can be provided to handle forwarding metrics live during invocations.\n\nOverwrite the `service` property on the `metrics` class to use a custom forwarding agent.\n\nAgents must be an object with a `save` method. This method is called with an array of metric values for each invocation.\n\n```javascript\nmetrics.service = {\n  save: metrics =\u003e {\n    // do some async save\n    return asyncServiceCall(metrics)\n  }\n}\n```\n\nMetric service agents can return a Promise for asynchronous operations.\n\n## issues / bugs / features?\n\nSomething gone wrong? OH NOES 😱!\n\nOpen an issue in the repository and I'll have a look… 💯\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjthomas%2Fopenwhisk-metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjthomas%2Fopenwhisk-metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjthomas%2Fopenwhisk-metrics/lists"}