docker

package
v0.0.0-...-c728838 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2017 License: MIT Imports: 13 Imported by: 0

README

Tail Docker Container Logs (using json-file driver)

Docker saves its container's output using the logging driver you specify. The default option is JSON file logging. Each line of stdout or stderr from your docker container is appended as a JSON object including a timestamp.

How to set it up:

  • docker run's --log-driver option should default to json-file, but maybe check to make sure you're not passing -–log-driver syslog
  • Add the following stanza to your config.json:
    "TailDockerJsonFiles": {
      "SecondsBetweenPollForNewContainers": 60,
      "InfluxDb": {
        "Hostname": "127.0.0.1",
        "Port": "8086",
        "DatabaseName": "mydb",
        "MeasurementName": "docker_logs"
      }
    },
    

If a log line appears to match Apache combined-log output, it will be parsed into separate fields.

Documentation

Index

Constants

View Source
const DEFAULT_SECONDS_BETWEEN_POLL_FOR_NEW_CONTAINERS = 60
View Source
const DOCKER_LOG_TIME_FORMAT = "2006-01-02T15:04:05.999999999Z"
View Source
const MAX_INFLUXDB_INSERT_BATCH_SIZE = 20000

Variables

View Source
var BRACKET_PREFIX_REGEX = regexp.MustCompile(`\[([^]]*)\]\s(.*)?`)
View Source
var COMBINED_LOG_FORMAT_REGEX = regexp.MustCompile(
	`^([0-9.]+)\s` +
		`([w.-]+)\s` +
		`([\w.-]+)\s` +
		`\[([^]]+)\]\s` +
		`"((?:[^"]|")+)"\s` +
		`(\d{3})\s` +
		`(\d+|-)\s` +
		`"((?:[^"])+)"\s` +
		`"((?:[^"]|")+)"`)
View Source
var DOCKER_LOG_LINE_REGEXP = regexp.MustCompile(
	"^([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{9}Z)" +
		"  (.*)\n$")
View Source
var INFLUXDB_TAGS_SET = map[string]bool{
	"image_name":  true,
	"status_code": true,
}
View Source
var LOGS_TIMEOUT = time.Duration(1 * time.Second)
View Source
var STREAM_TYPE_DESCRIPTIONS = []string{"STDIN", "STDOUT", "STDERR"}
View Source
var TAIL_LOG_LINE_FLUSH_TIMEOUT = time.Second

Functions

func TailDockerLogsForever

func TailDockerLogsForever(config *Options, configPath string)

func ValidateOptions

func ValidateOptions(options *Options)

Types

type JsonFileLog

type JsonFileLog struct {
	Log    string `json:"log"`
	Stream string `json:"stream"`
	Time   string `json:"time"`
}

type LogLine

type LogLine struct {
	ContainerId string
	ImageName   string
	StreamType  string
	Timestamp   time.Time
	Message     string
}

type Options

type Options struct {
	InfluxDb                           *influxdb.Options
	SecondsBetweenPollForNewContainers int
}

Jump to

Keyboard shortcuts

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