{"id":19874436,"url":"https://github.com/strongloop/strong-express-metrics","last_synced_at":"2025-05-02T10:31:12.784Z","repository":{"id":26559856,"uuid":"30013760","full_name":"strongloop/strong-express-metrics","owner":"strongloop","description":"An Express middleware for collecting HTTP statistics.","archived":false,"fork":false,"pushed_at":"2016-07-14T00:26:57.000Z","size":43,"stargazers_count":15,"open_issues_count":0,"forks_count":3,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-11-09T17:02:59.832Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/strongloop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-29T09:44:47.000Z","updated_at":"2018-06-25T18:28:30.000Z","dependencies_parsed_at":"2022-08-29T11:10:17.721Z","dependency_job_id":null,"html_url":"https://github.com/strongloop/strong-express-metrics","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-express-metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-express-metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-express-metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-express-metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strongloop","download_url":"https://codeload.github.com/strongloop/strong-express-metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224306997,"owners_count":17289728,"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":[],"created_at":"2024-11-12T16:23:18.881Z","updated_at":"2024-11-12T16:23:22.188Z","avatar_url":"https://github.com/strongloop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# strong-express-metrics\n\nAn Express middleware for collecting HTTP statistics.\n\n## Installation\n\n```\n$ npm install strong-express-metrics\n```\n\n## Usage\n\n```js\nvar express = require('express');\nvar metrics = require('strong-express-metrics');\n\nvar app = express();\napp.use(metrics());\napp.listen(3000);\n```\n\nYou can extend the metrics reported by the middleware by providing\na builder function. The output of this builder function will be merged\nwith the default record produced by the middleware.\n\n```js\napp.use(metrics(function buildRecord(req, res) {\n  return {\n    client: {\n      id: req.authInfo.app.id,\n      username: req.authInfo.user.email\n    },\n    data: {\n      // put your custom metrics here\n    }\n  };\n}));\n```\n\nIf your application is not running inside StrongLoop's Supervisor,\nyou can provide a custom function to process and report the statistics.\n\n```js\nmetrics.onRecord(function(data) {\n  // simple statsd output\n  console.log('url:%s|1|c', data.request.url);\n  console.log('status:%s|1|c', data.response.status);\n  console.log('response-time|%s|ms', data.duration);\n});\n```\n\n## Record format\n\nThe middleware produces records in the following format.\n\n```js\n{\n  version: require('./package.json').version,\n  timestamp: Date.now(),\n  client: {\n    address: req.socket.address().address,\n    id: undefined, // builder should override\n    username: undefined // builder should override\n  },\n  request: {\n    method: req.method,\n    url: req.url\n  },\n  response: {\n    status: res.statusCode,\n    duration: res.durationInMs,\n    bytes: undefined // TODO\n  },\n  process: {\n    pid: process.pid,\n    workerId: cluster.worker \u0026\u0026 cluster.workerId\n  },\n  data: {\n    // placeholder for user-provided data\n  },\n  // extra info filled for LoopBack applications only\n  loopback: {\n    modelName: 'User',\n    remoteMethod: 'prototype.updateAttributes',\n    // instanceId is undefined for static methods\n    // e.g. User.find() or User.login()\n    instanceId: 1234\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrongloop%2Fstrong-express-metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrongloop%2Fstrong-express-metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrongloop%2Fstrong-express-metrics/lists"}