npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eb-healthd-middleware

v1.0.1

Published

Middleware for enhanced health reporting in Elastic Beanstalk

Downloads

14

Readme

eb-healthd-middleware

When running Elastic Beanstalk in multi-container Docker mode the very useful enhanced health reporting does not work out of the box. There are several steps to configure it correctly and unfortunately they are not located in one document. Specifically, it requires one's application to log information about requests in a particular format and location.

This repo will detail those steps and provide Node.js middleware for Restify and Express to aid in logging appropriately.

Install

This module will only work with versions of Node 4 and above:

npm install eb-healthd-middleware --save

Setup

The first step is to create an .ebextensions folder that is uploaded in the same zip archive as your Dockerrun.aws.json file. Place the following yaml file (named 01-nginx-healthd.config) in .ebextensions ensuring the placeholder is replaced with the name of the container to be monitored. This informs the health monitoring agent as to where to find the logs on the host and also sets up a Cron job to periodically delete rotated logs.

files:
    "/etc/cron.hourly/cron.logcleanup.elasticbeanstalk.healthd.nginx.conf":
        mode: "000755"
        owner: root
        group: root
        content: |
            #!/bin/sh
            find /var/log/containers/<YOURCONTAINERNAME>/healthd -type f | grep -v application.log.`date -u +"%Y-%m-%d-%H"` | xargs rm -f
    "/home/ec2-user/setup-healthd-appstat.sh":
        mode: "000755"
        owner: root
        group: root
        content: |
            #!/bin/sh
            set -e
            mkdir -p /var/log/containers/<YOURCONTAINERNAME>/healthd
            chmod 777 /var/log/containers/<YOURCONTAINERNAME>/healthd
            if [ -d "/etc/healthd" ]
            then
                echo "appstat_log_path: /var/log/containers/<YOURCONTAINERNAME>/healthd/application.log" >> /etc/healthd/config.yaml
                echo "appstat_unit: sec" >> /etc/healthd/config.yaml
                echo "appstat_timestamp_on: completion" >> /etc/healthd/config.yaml
                initctl start healthd || initctl restart healthd
            fi

container_commands:
    01-healthd-configure:
        command: /home/ec2-user/setup-healthd-appstat.sh 

Once the host's logging location has been created we create mount points for the Docker container. The default logging location is usually /var/log/nginx but is configurable. One must edit the Dockerrun.aws.json to do so (note that the awseb-logs source volume is a preconfigured Elastic Beanstalk volume):

{
  "AWSEBDockerrunVersion": "2",
  "containerDefinitions": [{
    "name": "<YOURCONTAINERNAME>",
    "image": "mydocker/image:latest",
    "essential": "true",
    "memory": 1700,
    "portMappings": [{
      "hostPort": "80",
      "containerPort": "8080"
    }],
    "mountPoints": [
      {
        "sourceVolume": "awseb-logs-<YOURCONTAINERNAME>",
        "containerPath": "<LOGLOCATION>"
      }
    ]
  }]
}

Finally, one must log the requests as they come into the server. To do so we assign some simple middleware to log these in a file of the format /my/log/dir/application.log.yyyy-MM-dd-hh. Ensure that the log directory specified has been created in the Dockerfile.

For example, using Restify:

const restify = require('restify');
const ebHealth = require('eb-healthd-middleware');

const server = restify.createServer({
    name: 'myApi'
});
    
server.use(ebHealth({directory: '/my/log/dir'}));

Or with Express:

const express = require('express');
const ebHealth = require('eb-healthd-middleware');

const app = express();

// passing an empty options object will result in a default logging 
// directory of /var/log/nginx/healthd being used
app.use(ebHealth({}));