{"id":22273099,"url":"https://github.com/mac-/hapi-statsd","last_synced_at":"2025-07-28T14:31:48.769Z","repository":{"id":10569395,"uuid":"12774637","full_name":"mac-/hapi-statsd","owner":"mac-","description":"A hapi plugin for sending request round trip metrics to statsd","archived":false,"fork":false,"pushed_at":"2023-05-15T16:45:23.000Z","size":315,"stargazers_count":29,"open_issues_count":4,"forks_count":19,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-30T08:07:41.240Z","etag":null,"topics":["hapi","hapi-plugin","javascript","statsd-client"],"latest_commit_sha":null,"homepage":null,"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/mac-.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":"2013-09-12T04:09:40.000Z","updated_at":"2022-09-23T22:55:36.000Z","dependencies_parsed_at":"2024-06-21T17:39:24.942Z","dependency_job_id":"8fd4eb51-32ab-4013-ae2e-667ec82ec9b6","html_url":"https://github.com/mac-/hapi-statsd","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mac-%2Fhapi-statsd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mac-%2Fhapi-statsd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mac-%2Fhapi-statsd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mac-%2Fhapi-statsd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mac-","download_url":"https://codeload.github.com/mac-/hapi-statsd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227922961,"owners_count":17840940,"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":["hapi","hapi-plugin","javascript","statsd-client"],"created_at":"2024-12-03T13:09:45.428Z","updated_at":"2024-12-03T13:09:45.945Z","avatar_url":"https://github.com/mac-.png","language":"JavaScript","readme":"# hapi-statsd\n\n[![Build Status](https://secure.travis-ci.org/mac-/hapi-statsd.png)](http://travis-ci.org/mac-/hapi-statsd)\n[![Coverage Status](https://coveralls.io/repos/mac-/hapi-statsd/badge.png)](https://coveralls.io/r/mac-/hapi-statsd)\n[![Code Climate](https://codeclimate.com/github/mac-/hapi-statsd.png)](https://codeclimate.com/github/mac-/hapi-statsd)\n[![NPM version](https://badge.fury.io/js/hapi-statsd.png)](http://badge.fury.io/js/hapi-statsd)\n[![Dependency Status](https://david-dm.org/mac-/hapi-statsd.png)](https://david-dm.org/mac-/hapi-statsd)\n\n[![NPM](https://nodei.co/npm/hapi-statsd.png?downloads=true\u0026stars=true)](https://nodei.co/npm/hapi-statsd/)\n\nA hapi plugin for sending request round trip metrics to statsd, also exposing statsd client to the server.\n\n## Contributing\n\nThis module makes use of a `Makefile` for building/testing purposes. After obtaining a copy of the repo, run the following commands to make sure everything is in working condition before you start your work:\n\n\tmake install\n\tmake test\n\nBefore committing a change to your fork/branch, run the following commands to make sure nothing is broken:\n\n\tmake test\n\tmake test-cov\n\nDon't forget to bump the version in the `package.json` using the [semver](http://semver.org/spec/v2.0.0.html) spec as a guide for which part to bump. Submit a pull request when your work is complete.\n\n***Notes:***\n* Please do your best to ensure the code coverage does not drop. If new unit tests are required to maintain the same level of coverage, please include those in your pull request.\n* Please follow the same coding/formatting practices that have been established in the module.\n\n## Installation\n\n\tnpm install hapi-statsd\n\n## Usage\n\nTo install this plugin on your Hapi server, do something similar to this:\n\n```js\nvar Hapi = require('@hapi/hapi');\nvar server = new Hapi.Server();\n\nvar hapiStatsdConfig = {};\n\nserver.register({ register: require('hapi-statsd'), options: hapiStatsdConfig }, function(err) {\n\tif (err) {\n\t\tconsole.log('error', 'Failed loading plugin: hapi-statsd');\n\t}\n});\n```\n\n## Plugin Options\n\n### `template`\n\nA template to use for the stat names to send to statsd. This can be any string that could include the following tokens that get replaced with their actual values:\n\n* `{path}` - the path that the request was routed to (e.g `'/users/{id}'`)\n* `{method}` - the HTTP verb used on the request (e.g. `'GET'`)\n* `{statusCode}` - the numerical status code of the response that the server sent back to the client (e.g. `200`)\n\nDefaults to `'{path}.{method}.{statusCode}'`\n\n### `statsdClient`\n\nAn instance of a particular statsd client that you prefer to use for sending metrics to statsd. If this is used, then the `statsdHost` and `prefix` options are ignored. Defaults to `null`\n\n### `host`\n\nThe host athat an instance of statsd is running on. An instance of the `statsd-client` NPM module will be created and will be configured to use this host. Defaults to `'localhost'`\n\n### `port`\n\nThe port that an instance of statsd is listening on. An instance of the `statsd-client` NPM module will be created and will be configured to use this port. Defaults to `8125`\n\n### `prefix`\n\nThe prefix to add to every stat collected. Usually used for grouping a set of stats under one hierarchy in graphite. Defaults to `'hapi'`\n\n### `pathSeparator`\n\nA character or set of characters to replace the '/' (forward slash) characters in your URL path since forward slashes cannot be used in stat names. Defaults to `'_'`\n\n### `defaultFilter`\n\nDefines whether increment and timer stats are turned on by default. Defaults to `{ enableCounter: true, enableTimer: true }`.\n\n### `filters`\n\nAn array of custom filters. A successful match requires one of these fields to be defined and match the route: \n* `id`: The route id defined in the route's config\n* `path`: The path defined in the route\n* `method`: The HTTP method of the request/route\n* `status`: The returned HTTP status code of the response\n \nParameters that are not included are considered wildcard and will match all values. Note that if none of these \nparameters are included in the filter, then you will get a match on ALL route-response combinations.\n\nIn addition to matching, the field can contain the following configuration options:\n\n* name: Defines a custom name for the stat to be reported\n* enableTimer: Enable/disable the timer stat from being reported\n* enableCounter: Enable/disable the count stat from being reported\n\nExample configuration:\n```js\ndefaultFilter: { // by default, enable timer and disable counter stats\n    enableCounter: false,\n    enableTimer: true,\n}\nfilters: [\n    { path: '/', enableCounter: true }, // enable counters (keep timers on as well) for this path\n    { path: '/test/{param}', enableCounter: true }, // path with a parameter\n    { path: '/rename', name: 'rename_stat' }, // rename the metric\n    { id: 'match-my-id', enableCounter: true, enableTimer: true }, // match by route id\n    { status: 407, name: 'match_on_status', enableCounter: true, enableTimer: true }, // match by status code\n]\n````\n\n## Example\n\nA Hapi route configured like this:\n\n```js\nserver.route({\n\tmethod: 'GET',\n\tpath: '/test/{param}',\n\thandler: function(request, reply) {\n\t\treply('Success!');\n\t}\n});\n```\n\nwould send an increment and timing stat to statsd with the following stat name (assuming all options are set to their defaults):\n\n\thapi.test_{param}.GET.200\n\nAs the [statsd client](https://github.com/msiebuhr/node-statsd-client) is also exposed to the hapi server, you can use any of its methods, e.g.:\n\n```js\nserver.statsd.increment('systemname.subsystem.value');\nserver.statsd.gauge('what.you.gauge', 100);\nserver.statsd.set('your.set', 200);\n```\n\n## Version Compatibility\n\n### Currently compatible with: Hapi 20.x.x\n\n* 0.1.x - Hapi 1.x.x\n* 0.2.x - Hapi 3.x.x\n* 0.3.x - Hapi 3.x.x\n* 0.4.x - Hapi 4.x.x\n* 1.0.x - Hapi 6.x.x\n* 1.1.x - Hapi 7.x.x\n* 1.2.x - Hapi 8.x.x\n* 2.x.x - Hapi 9.x.x\n* 3.x.x - Hapi 10.x.x (Node v4)\n* 4.x.x - Hapi 11.x.x\n* 5.x.x - Hapi 13.x.x\n* 6.x.x - Hapi 16.x.x\n* 7.x.x - Hapi 17.x.x (Node v8)\n* 8.x.x - Hapi 18.x.x\n* 9.x.x - Hapi 20.x.x (Node v12)\n\n# License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Mac Angell\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmac-%2Fhapi-statsd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmac-%2Fhapi-statsd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmac-%2Fhapi-statsd/lists"}