Skip to content

Commit

Permalink
Merge pull request #192 from gliderlabs/master
Browse files Browse the repository at this point in the history
v3.1
  • Loading branch information
michaelshobbs committed May 23, 2016
2 parents 927ba2a + 19fa188 commit ca675f3
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 30 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ All notable changes to this project will be documented in this file.

### Changed

## [v3.1] - 2016-05-23
### Fixed
- Panic when renaming stopped container #183
- won't start without route configuration #185
- RouteManager.Name() didn't return name
### Added
- update container name if we get a rename event. closes #144 (#180)

### Removed

### Changed
- Now using Alpine Linux 3.3 and GO 1.5.3, removed the "edge" package repo for building the official Docker image (#174)
- Fix exposed ports in Dockerfile and readme. Remove references to /tmp/docker.sock from readme

## [v3] - 2016-03-03
### Fixed
Expand Down Expand Up @@ -80,6 +93,7 @@ All notable changes to this project will be documented in this file.
- Base container is now Alpine
- Moved to gliderlabs organization

[unreleased]: https://github.com/gliderlabs/logspout/compare/v3...HEAD
[unreleased]: https://github.com/gliderlabs/logspout/compare/v3.1...HEAD
[v3.1]: https://github.com/gliderlabs/logspout/compare/v3...v3.1
[v3]: https://github.com/gliderlabs/logspout/compare/v2...v3
[v2]: https://github.com/gliderlabs/logspout/compare/v1...v2
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM gliderlabs/alpine:3.1
FROM gliderlabs/alpine:3.3
ENTRYPOINT ["/bin/logspout"]
VOLUME /mnt/routes
EXPOSE 8000
EXPOSE 80

COPY . /src
RUN cd /src && ./build.sh "$(cat VERSION)"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM gliderlabs/alpine:3.1
FROM gliderlabs/alpine:3.3
VOLUME /mnt/routes
EXPOSE 8000
EXPOSE 80

ENV GOPATH /go
RUN apk-install go git mercurial
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ ifneq ($(CIRCLE_BRANCH), release)
echo build-$$CIRCLE_BUILD_NUM > VERSION
endif

.PHONY: release
clean:
rm -rf build/
docker rm $(shell docker ps -aq) || true
docker rmi $(NAME):dev $(NAME):$(VERSION) || true
docker rmi $(shell docker images -f 'dangling=true' -q) || true

.PHONY: release clean
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ For now it only captures stdout and stderr, but a module to collect container sy

## Getting logspout

Logspout is a very small Docker container (14MB virtual, based on [Alpine](https://github.com/gliderlabs/docker-alpine)). Pull the latest release from the index:
Logspout is a very small Docker container (15.2MB virtual, based on [Alpine](https://github.com/gliderlabs/docker-alpine)). Pull the latest release from the index:

$ docker pull gliderlabs/logspout:latest

Expand All @@ -26,10 +26,10 @@ You can also download and load a specific version:

#### Route all container output to remote syslog

The simplest way to use logspout is to just take all logs and ship to a remote syslog. Just pass a syslog URI (or several comma separated URIs) as the command. Also, we always mount the Docker Unix socket with `-v` to `/tmp/docker.sock`:
The simplest way to use logspout is to just take all logs and ship to a remote syslog. Just pass a syslog URI (or several comma separated URIs) as the command. Also, we always mount the Docker Unix socket with `-v` to `/var/run/docker.sock`:

$ docker run --name="logspout" \
--volume=/var/run/docker.sock:/tmp/docker.sock \
--volume=/var/run/docker.sock:/var/run/docker.sock \
gliderlabs/logspout \
syslog://logs.papertrailapp.com:55555

Expand All @@ -48,8 +48,8 @@ You can tell logspout to ignore specific containers by setting an environment va
Using the [httpstream module](http://github.com/gliderlabs/logspout/blob/master/httpstream), you can connect with curl to see your local aggregated logs in realtime. You can do this without setting up a route URI.

$ docker run -d --name="logspout" \
--volume=/var/run/docker.sock:/tmp/docker.sock \
--publish=127.0.0.1:8000:8000 \
--volume=/var/run/docker.sock:/var/run/docker.sock \
--publish=127.0.0.1:8000:80 \
gliderlabs/logspout
$ curl http://127.0.0.1:8000/logs

Expand Down Expand Up @@ -87,9 +87,21 @@ The standard distribution of logspout comes with all modules defined in this rep

### Third-party modules

* logspout-kafka...
* [logspout-kafka](https://github.com/gettyimages/logspout-kafka)
* logspout-redis...
* [logspout-logstash](https://github.com/looplab/logspout-logstash)
* [logspout-redis-logstash](https://github.com/rtoma/logspout-redis-logstash)

### Loggly support

Use logspout to stream your docker logs to Loggly via the [Loggly syslog endpoint](https://www.loggly.com/docs/streaming-syslog-without-using-files/).
```
$ docker run --name logspout -d --volume=/var/run/docker.sock:/var/run/docker.sock \
-e SYSLOG_STRUCTURED_DATA="<Loggly API Key>@41058 tag=\"some tag name\"" \
gliderlabs/logspout \
syslog+tcp://logs-01.loggly.com:514
```


## Contributing

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3
v3.1
41 changes: 26 additions & 15 deletions router/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,22 @@ func (p *LogsPump) Name() string {
}

func (p *LogsPump) Setup() error {
client, err := docker.NewClient(
getopt("DOCKER_HOST", "unix:///var/run/docker.sock"))
if err != nil {
return err
var err error
p.client, err = docker.NewClientFromEnv()
return err
}

func (p *LogsPump) rename(event *docker.APIEvents) {
p.mu.Lock()
defer p.mu.Unlock()
container, err := p.client.InspectContainer(event.ID)
assert(err, "pump")
pump, ok := p.pumps[normalID(event.ID)]
if !ok {
debug("pump.rename(): ignore: pump not found, state:", container.State.StateString())
return
}
p.client = client
return nil
pump.container.Name = container.Name
}

func (p *LogsPump) Run() error {
Expand All @@ -106,10 +115,12 @@ func (p *LogsPump) Run() error {
return err
}
for event := range events {
debug("pump: event:", normalID(event.ID), event.Status)
debug("pump.Run() event:", normalID(event.ID), event.Status)
switch event.Status {
case "start", "restart":
go p.pumpLogs(event, true)
case "rename":
go p.rename(event)
case "die":
go p.update(event)
}
Expand All @@ -122,11 +133,11 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents, backlog bool) {
container, err := p.client.InspectContainer(id)
assert(err, "pump")
if container.Config.Tty {
debug("pump:", id, "ignored: tty enabled")
debug("pump.pumpLogs():", id, "ignored: tty enabled")
return
}
if ignoreContainer(container) {
debug("pump:", id, "ignored: environ ignore")
debug("pump.pumpLogs():", id, "ignored: environ ignore")
return
}
var tail string
Expand All @@ -141,7 +152,7 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents, backlog bool) {
p.pumps[id] = newContainerPump(container, outrd, errrd)
p.mu.Unlock()
p.update(event)
debug("pump:", id, "started")
debug("pump.pumpLogs():", id, "started")
go func() {
err := p.client.Logs(docker.LogsOptions{
Container: id,
Expand All @@ -153,7 +164,7 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents, backlog bool) {
Tail: tail,
})
if err != nil {
debug("pump:", id, "stopped:", err)
debug("pump.pumpLogs():", id, "stopped:", err)
}
outwr.Close()
errwr.Close()
Expand All @@ -168,11 +179,11 @@ func (p *LogsPump) update(event *docker.APIEvents) {
defer p.mu.Unlock()
pump, pumping := p.pumps[normalID(event.ID)]
if pumping {
for r, _ := range p.routes {
for r := range p.routes {
select {
case r <- &update{event, pump}:
case <-time.After(time.Second * 1):
debug("pump: route timeout, dropping")
debug("pump.update(): route timeout, dropping")
defer delete(p.routes, r)
}
}
Expand Down Expand Up @@ -247,7 +258,7 @@ func newContainerPump(container *docker.Container, stdout, stderr io.Reader) *co
line, err := buf.ReadString('\n')
if err != nil {
if err != io.EOF {
debug("pump:", normalID(container.ID), source+":", err)
debug("pump.newContainerPump():", normalID(container.ID), source+":", err)
}
return
}
Expand All @@ -274,7 +285,7 @@ func (cp *containerPump) send(msg *Message) {
select {
case logstream <- msg:
case <-time.After(time.Second * 1):
debug("pump: send timeout, closing")
debug("pump.send(): send timeout, closing")
// normal call to remove() triggered by
// route.Closer() may not be able to grab
// lock under heavy load, so we delete here
Expand Down
8 changes: 6 additions & 2 deletions router/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (rm *RouteManager) RoutingFrom(containerID string) bool {

func (rm *RouteManager) Run() error {
rm.Lock()
defer rm.Unlock()
for _, route := range rm.routes {
rm.wg.Add(1)
go func(route *Route) {
Expand All @@ -170,13 +171,16 @@ func (rm *RouteManager) Run() error {
}(route)
}
rm.routing = true
rm.Unlock()
rm.wg.Wait()
// Temp fix to allow logspout to run without routes defined.
if len(rm.routes) == 0 {
select {}
}
return nil
}

func (rm *RouteManager) Name() string {
return ""
return "routes"
}

func (rm *RouteManager) Setup() error {
Expand Down

0 comments on commit ca675f3

Please sign in to comment.