Docker CE and syslog - docker

Docker logging drivers are specified online, and these limitations.
Limitations of logging drivers
Users of Docker Enterprise can make use of “dual logging”, which enables you to use the docker logs command for any logging driver. Refer to reading logs when using remote logging drivers for information about using docker logs to read container logs locally for many third party logging solutions, including:
syslog
gelf
fluentd
awslogs
splunk
etwlogs
gcplogs
Logentries
When using Docker Community Engine, the docker logs command is only available on the following drivers:
local
json-file
journald
Reading log information requires decompressing rotated log files, which causes a temporary increase in disk usage (until the log entries from the rotated files are read) and an increased CPU usage while decompressing.
The capacity of the host storage where the Docker data directory resides determines the maximum size of the log file information.
I am using Docker CE, but I have a question about this documentation. Does this mean, using CE, I cant do syslog at all? or just that I cant do syslog and have docker logs?

There is nothing stopping you from using syslog within the container, but you can't read those logs using the 'docker logs' command. There is also nothing stopping you from writing your logs to stdout and piping your logs to as many log shippers as you want.
Here's an article that explains how to do syslog in a docker container: https://medium.com/better-programming/docker-centralized-logging-with-syslog-97b9c147bd30
I think that fluentd and fluent-bit are better choices than syslog these days given the structure they provide to the msg field, though syslog-ng looks interesting. Fluent-bit is incredibly good though, so you might want to take a look at it.

Related

Docker + Fluentd in K8s for log rotation: Does Docker need to know the existence of Fluentd?

I am trying to understand the interaction between Docker and Fluentd in a K8s cluster. I have seen places where you need to configure Docker to output to a logging driver, and Fluentd can be used as logging driver, like here.
On the other hand, I have seen posts (like this or this) where Docker does not know the existence of Fluentd as a DaemonSet.
My whole intention is to do log rotation, however I am not sure if having Fluentd in place will actually rotate the logs Docker writes on, so I do not end up with the whole storage space in the node taken up by the logs over time. Is it enough to use FluentD DaemonSet without Docker knowing the existence of Fluentd?, o I need to somehow connect Docker to Fluentd with a driver as well?
Per official k8s logging architecture docker (or any other runtime) does not need to know about FluentBit, Fluentd, Filebeat, or any other log collector you use. In fact, you can use multiple log collectors a time!
The same document states that k8s is not responsible for log rotation, so you set up a logrotate yourself. Fluentd/FluentBit daemon on the other end also does not rotate log files, but it does able to track log rotation and adjust the tail cursor accordingly (by default).
By far the easiest way to implement the architecture is
Leave kubelet & docker settings at default
Ensure the app logs stdout/stderr
Ensure there's logrotate: many k8s worker AMIs, e.g. EKS already have it.
Setup FluentBit log collector daemonset https://github.com/helm/charts/tree/master/stable/fluent-bit

How to forward application logs to Splunk from docker container?

We're interested in forwarding the logs from a node.js server running in a Docker container to Splunk.
Some options we've considered include a side-car container running a Splunk forwarder. The side-car would write to a shared volume that the side-car would observe and send on.
Ideally, we would just use a syslog drain or another mechanism, but I can't seem to find any documentation on how to set that up?
There are a lot of options to send logs from containers to Splunk.
For logs, sent to Standard Output and Error:
Splunk Logging Driver https://docs.docker.com/v17.09/engine/admin/logging/splunk/
Splunk Docker logging plugin https://github.com/splunk/docker-logging-plugin - an improved version of Splunk Logging Driver
For application logs (logs written inside of the container):
Sidecars with UF
Our company (https://www.outcoldsolutions.com) offers one solution that can simply forward container (https://www.outcoldsolutions.com/docs/monitoring-docker/v5/) and application logs (https://www.outcoldsolutions.com/docs/monitoring-docker/v5/annotations/#application-logs) from the Docker hosts, and collect metrics. We also provide you with an application in Splunk for tracking the health and performance of your clusters https://splunkbase.splunk.com/app/3723/. Our application is not free, but cheap compared to the time you can spend building something similar.
Another option is using fluentd as an intermediary.
Fluentd exists as docker logging driver as well, but you can use it to redirect the logs to several backends (Splunk, Elasticsearch). You are not as tightly coupled to Splunk.
Additionally that's the way proposed by Openshift.
It looks like Docker has a logging driver that handles this
https://docs.docker.com/v17.09/engine/admin/logging/splunk/

Where do docker logs go when splunk server is not reachable

I am trying to get docker logs from a running docker container. I have configured splunk as logging driver in my docker compose and I understand that if splunk server is not reachable then container won't start.
proxysecurity:
image: test/image
network_mode: host
depends_on:
- zookeeper
ports:
- '8083:8083'
logging:
driver: "splunk"
options:
splunk-url: "http://XX.X2.X3.X1:XXX7/"
splunk-token: "XXXXX5-9CA1-44B8-B9E8-2XXX25"
splunk-format: json
tag: "{{.ImageName}}/{{.Name}}/{{.ID}}"
environment:
XXXCONNECT: localhost:32181
XXXXXRS: http://localhost:8083
Now if splunk server is not reachable when container is up and running , is there any fall back mechanism wherein we can tell docker container to log locally ?
Or is there any way to log to splunk as well as locally inside container ?
I am the author of the Splunk Logging Driver.
In case if Splunk is unavailable, driver holds small buffer in memory and keeps retrying. Configuration for the size of the buffer is documented no official docs for the driver https://docs.docker.com/engine/admin/logging/splunk/
SPLUNK_LOGGING_DRIVER_BUFFER_MAX
If driver cannot connect to remote server, what is the maximum amount of messages it can hold in buffer for retries.
Unfortunately this is not ideal, considering that this buffer can be filled pretty quickly and that increasing the buffer to higher number can affect your containers. But this is how most of the drivers written.
I have built another solution delivering logs and metrics to Splunk. This solution includes tiny image with collector and Splunk Certified Application. It is built on top of json-file driver, which means that when Splunk is unavailable it will just keep retrying from the position of the log files. The logs files can have their own settings for rotation, this can be configured with dockerd daemon configuration. You can read another benefits of our solution Comparing with Splunk Logging Driver. And how to get started with Monitoring Docker.

GELF logging driver with Windows Containers

I'm trying get an ELK stack up (Elastic Search, Logstash and Kibana) and would like to get the GELF logging driver to forward events to Logstash, however whenever I run my container with the specified driver I get docker: Error response from daemon: logger: no log driver named 'gelf' is registered. even though I'm on 1.12.2-cs2-ws-beta. Is there a way to get this working on Windows Server 2016?
The supported log drivers section does list GELF (Graylog Extended Log Format), but by default on docker for Linux (so within a Linux VM on other platforms)
The official GELF documention does recommend in its installation page
Some modern Linux distribution (Debian Linux, Ubuntu Linux, or CentOS recommended)
So a Windows server 2016 might not include a Graylog server in its Docker.

How to start Splunk Forwarder within a script

I would like to start to monitor our dockers with Splunk. To do it I want to add it to the docker buildfile.
The issue is that if its the first time you start the forwarder, it prompts you to agree for the license agreement, which breaks the script.
Is there a way to start the Splunk forwarder without being prompted?
The arguments you are looking for are --accept-license --answer-yes --no-prompt.
A Splunk employee publishes some Docker images on his own time that can cater for this already. Have a look at SPLUNK_START_ARGS in the forwarders entrypoint.sh.
Also, Docker natively supports sending its own logs to Splunk. This includes the stdout and stderr of all containers so you may not need your own forwarder.

Resources