{"id":16841763,"url":"https://github.com/svozza/eb-healthd-middleware","last_synced_at":"2025-06-17T10:35:14.990Z","repository":{"id":50919279,"uuid":"78004750","full_name":"svozza/eb-healthd-middleware","owner":"svozza","description":null,"archived":false,"fork":false,"pushed_at":"2019-10-29T03:40:35.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-13T13:11:49.391Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/svozza.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":"2017-01-04T10:12:18.000Z","updated_at":"2021-03-30T21:50:07.000Z","dependencies_parsed_at":"2022-08-28T08:22:27.461Z","dependency_job_id":null,"html_url":"https://github.com/svozza/eb-healthd-middleware","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/svozza/eb-healthd-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svozza%2Feb-healthd-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svozza%2Feb-healthd-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svozza%2Feb-healthd-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svozza%2Feb-healthd-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svozza","download_url":"https://codeload.github.com/svozza/eb-healthd-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svozza%2Feb-healthd-middleware/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259827306,"owners_count":22917686,"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-10-13T12:42:57.536Z","updated_at":"2025-06-17T10:35:09.968Z","avatar_url":"https://github.com/svozza.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eb-healthd-middleware\n\nWhen running Elastic Beanstalk in multi-container Docker mode the very \nuseful enhanced health reporting does not work out of the box. There are \nseveral steps to configure it correctly and unfortunately they are not\nlocated in one document. Specifically, it requires one's application to \nlog information about requests in a [particular format and location][1].\n\nThis repo will detail those steps and provide Node.js middleware for \n[Restify](http://restify.com/) and [Express](http://expressjs.com/) to \naid in logging appropriately.\n\n## Install\n\nThis module will only work with versions of Node 4 and above:\n\n`npm install eb-healthd-middleware --save`\n\n## Setup\n\nThe first step is to create an `.ebextensions` folder that is uploaded\nin the same zip archive as your `Dockerrun.aws.json` file. Place the\nfollowing yaml file (named `01-nginx-healthd.config`) in `.ebextensions` \nensuring the placeholder is replaced with the name of the container to \nbe monitored. This informs the health monitoring agent as to where to \nfind the logs on the host and also sets up a Cron job to periodically \ndelete rotated logs.\n\n```yaml\nfiles:\n    \"/etc/cron.hourly/cron.logcleanup.elasticbeanstalk.healthd.nginx.conf\":\n        mode: \"000755\"\n        owner: root\n        group: root\n        content: |\n            #!/bin/sh\n            find /var/log/containers/\u003cYOURCONTAINERNAME\u003e/healthd -type f | grep -v application.log.`date -u +\"%Y-%m-%d-%H\"` | xargs rm -f\n    \"/home/ec2-user/setup-healthd-appstat.sh\":\n        mode: \"000755\"\n        owner: root\n        group: root\n        content: |\n            #!/bin/sh\n            set -e\n            mkdir -p /var/log/containers/\u003cYOURCONTAINERNAME\u003e/healthd\n            chmod 777 /var/log/containers/\u003cYOURCONTAINERNAME\u003e/healthd\n            if [ -d \"/etc/healthd\" ]\n            then\n                echo \"appstat_log_path: /var/log/containers/\u003cYOURCONTAINERNAME\u003e/healthd/application.log\" \u003e\u003e /etc/healthd/config.yaml\n                echo \"appstat_unit: sec\" \u003e\u003e /etc/healthd/config.yaml\n                echo \"appstat_timestamp_on: completion\" \u003e\u003e /etc/healthd/config.yaml\n                initctl start healthd || initctl restart healthd\n            fi\n\ncontainer_commands:\n    01-healthd-configure:\n        command: /home/ec2-user/setup-healthd-appstat.sh \n```\n\nOnce the host's logging location has been created we create mount points\nfor the Docker container. The default logging location is usually\n`/var/log/nginx` but is configurable. One must edit the\n`Dockerrun.aws.json` to do so (note that the `awseb-logs` source volume\nis a preconfigured Elastic Beanstalk volume):\n\n```json\n{\n  \"AWSEBDockerrunVersion\": \"2\",\n  \"containerDefinitions\": [{\n    \"name\": \"\u003cYOURCONTAINERNAME\u003e\",\n    \"image\": \"mydocker/image:latest\",\n    \"essential\": \"true\",\n    \"memory\": 1700,\n    \"portMappings\": [{\n      \"hostPort\": \"80\",\n      \"containerPort\": \"8080\"\n    }],\n    \"mountPoints\": [\n      {\n        \"sourceVolume\": \"awseb-logs-\u003cYOURCONTAINERNAME\u003e\",\n        \"containerPath\": \"\u003cLOGLOCATION\u003e\"\n      }\n    ]\n  }]\n}\n```\n\nFinally, one must log the requests as they come into the server. To do \nso we assign some simple middleware to log these in a file of the format\n`/my/log/dir/application.log.yyyy-MM-dd-hh`. Ensure that the log\ndirectory specified has been created in the `Dockerfile`.\n\nFor example, using Restify:\n\n```js\nconst restify = require('restify');\nconst ebHealth = require('eb-healthd-middleware');\n\nconst server = restify.createServer({\n    name: 'myApi'\n});\n    \nserver.use(ebHealth({directory: '/my/log/dir'}));\n```\n\nOr with Express:\n\n```js\nconst express = require('express');\nconst ebHealth = require('eb-healthd-middleware');\n\nconst app = express();\n\n// passing an empty options object will result in a default logging \n// directory of /var/log/nginx/healthd being used\napp.use(ebHealth({}));\n```\n\n[1]: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/health-enhanced-serverlogs.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvozza%2Feb-healthd-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvozza%2Feb-healthd-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvozza%2Feb-healthd-middleware/lists"}