kafka

package module
v0.0.0-...-a6c2713 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2017 License: MIT Imports: 15 Imported by: 0

README

logspout-kafka

A Logspout adapter for writing Docker container logs to Kafka topics.

This project has extension for github fork upstream. More information refer here.

usage

With container-logs as the Kafka topic for Docker container logs, we can direct all messages to Kafka using the logspout Route API:

curl http://container-host:8000/routes -d '{
  "adapter": "kafka",
  "filter_sources": ["stdout" ,"stderr"],
  "address": "kafka-broker1:9092,kafka-broker2:9092/container-logs"
}'

message template configuration

The default behavior is to route the raw message to Kafka. This adapter provides a mechanism for customizing the template to include additional metadata via the KAFKA_TEMPLATE environment variable. Golang's text/template package is used for templating, where the model available for templating is the Message struct.

The following example KAFKA_TEMPLATE configuration appends additional metadata to each log message received:

KAFKA_TEMPLATE="time=\"{{.Time}}\" container_name=\"{{.Container.Name}}\" source=\"{{.Source}}\" data=\"{{.Data}}\""

Example input and output

Hello World

time="2015-06-23 09:54:55.241951004 +0000 UTC" container_name="/hello_container" source="stdout" data="Hello World"

route configuration

If you've mounted a volume to /mnt/routes, then consider pre-populating your routes. The following script configures a route to send standard messages from a "cat" container to one Kafka topic, and a route to send standard/error messages from a "dog" container to another topic.

cat > /logspout/routes/cat.json <<CAT
{
  "id": "cat",
  "adapter": "kafka",
  "filter_name": "cat_*",
  "filter_sources": ["stdout"],
  "address": "kafka-broker1:9092,kafka-broker2:9092/cat-logs"
}
CAT

cat > /logspout/routes/dog.json <<DOG
{
  "id": "dog",
  "adapter": "kafka",
  "filter_name": "dog_*",
  "filter_sources": ["stdout", "stderr"],
  "address": "kafka-broker1:9092,kafka-broker2:9092/dog-logs"
}
DOG

docker run --name logspout \
  -p "8000:8000" \
  --volume /logspout/routes:/mnt/routes \
  --volume /var/run/docker.sock:/tmp/docker.sock \
  fengzhou/logspout

The routes can be updated on a running container by using the logspout Route API and specifying the route id "cat" or "dog".

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewKafkaAdapter

func NewKafkaAdapter(route *router.Route) (router.LogAdapter, error)

Types

type DockerInfo

type DockerInfo struct {
	ContainerId     string
	ContainerFullId string
	ContainerName   string
	ImageId         string
	ImageName       string
	HostId          string
	HostName        string
	HostAddr        string
	HostIp          string
	Command         string
	Stack           string // or project for docker compose
	Service         string // or service for docker compose
}

type KafkaAdapter

type KafkaAdapter struct {
	// contains filtered or unexported fields
}

func (*KafkaAdapter) Stream

func (a *KafkaAdapter) Stream(logstream chan *router.Message)

type KafkaMessage

type KafkaMessage struct {
	*router.Message
	Envs  *map[string]string
	Info  *DockerInfo
	Level int32
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL