├── Dockerfile ├── LICENSE ├── README.md ├── build.sh ├── ecs-entry.sh ├── ecs └── logspout-ecs-task.json └── modules.go /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gliderlabs/logspout:v3.2.8 2 | 3 | ENTRYPOINT ["/ecs-entry.sh"] 4 | 5 | COPY ecs-entry.sh /ecs-entry.sh 6 | RUN chmod +x /ecs-entry.sh 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT license 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2015 Signiant Inc. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # logspout-ecs 2 | specialization of the logspout container modified to set the hostname including the instance ID on ECS 3 | 4 | This small tweak runs a small shell script before invoking logspout to get the instance ID from the EC2 metatdata. It then appends that to whatever is passed in as the SYSLOG_HOSTNAME environment variable to use the final value as the syslog hostname. If not SYSLOG_HOSTNAME variable is present, the syslog hostname is just set to the hostname as per default logspout behaviour. 5 | 6 | This is useful when running on AWS ECS and sending logs to papertrail because you can then see which ECS cluster node your container is running on. 7 | 8 | Ensure you pass in SYSLOG_HOSTNAME as an environment variable. 9 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | apk add --update go build-base git mercurial ca-certificates 4 | mkdir -p /go/src/github.com/gliderlabs 5 | cp -r /src /go/src/github.com/gliderlabs/logspout 6 | cd /go/src/github.com/gliderlabs/logspout 7 | export GOPATH=/go 8 | go get github.com/Masterminds/glide && $GOPATH/bin/glide install 9 | go build -ldflags "-X main.Version=$1" -o /bin/logspout 10 | apk del go git mercurial build-base 11 | rm -rf /go /var/cache/apk/* /root/.glide 12 | 13 | # backwards compatibility 14 | ln -fs /tmp/docker.sock /var/run/docker.sock 15 | -------------------------------------------------------------------------------- /ecs-entry.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # get the AWS instance ID 4 | if [ ! -z "$OFF_AWS" ]; then 5 | echo "Not running on AWS - will not get the instance ID" 6 | else 7 | INST=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id` 8 | fi 9 | 10 | # append the instance ID to an already set syslog hostname 11 | if [ ! -z "$INST" ]; then 12 | if [ ! -z "$SYSLOG_HOSTNAME" ]; then 13 | SYSLOG_HOSTNAME=${SYSLOG_HOSTNAME}_$INST 14 | fi 15 | else 16 | SYSLOG_HOSTNAME=${SYSLOG_HOSTNAME} 17 | fi 18 | 19 | /bin/logspout "$@" 20 | -------------------------------------------------------------------------------- /ecs/logspout-ecs-task.json: -------------------------------------------------------------------------------- 1 | { 2 | "family": "logspout-dev", 3 | "volumes": [ 4 | { 5 | "name": "dockersock", 6 | "host": { 7 | "sourcePath": "/var/run/docker.sock" 8 | } 9 | } 10 | ], 11 | "containerDefinitions": [ 12 | { 13 | "name": "logspout-task", 14 | "image": "signiant/logspout-ecs:latest", 15 | "cpu": 10, 16 | "memory": 10, 17 | "portMappings": [ 18 | { 19 | "containerPort": 8000, 20 | "hostPort": 8000 21 | } 22 | ], 23 | "command": [ 24 | "syslog://logs2.papertrailapp.com:" 25 | ], 26 | "environment": [ 27 | { "name": "SYSLOG_HOSTNAME", "value": "logspout-dev" }, 28 | { "name": "SYSLOG_FORMAT", "value": "rfc3164" } 29 | ], 30 | "essential": true, 31 | "mountPoints": [ 32 | { 33 | "sourceVolume": "dockersock", 34 | "containerPath": "/tmp/docker.sock" 35 | } 36 | ] 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /modules.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "github.com/gliderlabs/logspout/adapters/raw" 5 | _ "github.com/gliderlabs/logspout/adapters/syslog" 6 | _ "github.com/gliderlabs/logspout/httpstream" 7 | _ "github.com/gliderlabs/logspout/routesapi" 8 | _ "github.com/gliderlabs/logspout/transports/tcp" 9 | _ "github.com/gliderlabs/logspout/transports/udp" 10 | _ "github.com/gliderlabs/logspout/transports/tls" 11 | ) 12 | --------------------------------------------------------------------------------