-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker Log Plugin #4360
Docker Log Plugin #4360
Conversation
Any idea when this plugin would be available? @prashanthjbabu Awesome work here :) |
@Puneeth-n Thank you :) ! |
Any ETA on merging? That'd be brilliant. Thanks a lot for PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
## Only collect metrics for these containers. Values will be appended to | ||
## container_name_include. | ||
## Deprecated (1.4.0), use container_name_include | ||
container_names = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this config option as there isn't much value in replicating deprecated options from the docker
plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care of this!
|
||
- docker_log | ||
- tags: | ||
- containerId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe container_name
, as it would match the docker
plugin better and be more human friendly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added containerName and kept containerId as well just incase it is used for matching
} | ||
|
||
func NewEnvClient() (Client, error) { | ||
client, err := docker.NewEnvClient() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this is deprecated and should be NewClientWithOpts(FromEnv)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care of this!
sockets.ConfigureTransport(transport, proto, addr) | ||
httpClient := &http.Client{Transport: transport} | ||
|
||
client, err := docker.NewClient(host, version, httpClient, defaultHeaders) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewClient
is also deprecated in favor of NewClientWithOpts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care of this!
|
||
type DockerLogs struct { | ||
Endpoint string | ||
ContainerNames []string // deprecated in 1.4; use container_name_include |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove ContainerNames
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care of this!
ctx, cancel := context.WithTimeout(context.Background(), d.Timeout.Duration) | ||
defer cancel() | ||
if d.client == nil { | ||
log.Println("ERR:Dock client is null") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use telegraf error logging syntax - E! Error to log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care of this!
} | ||
|
||
func (d *DockerLogs) addToContainerList(containerId string, logReader io.ReadCloser) error { | ||
d.containerList[containerId] = logReader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should lock around the read/writes of this map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care of this!
} | ||
} | ||
} | ||
func (d *DockerLogs) Start(acc telegraf.Accumulator) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a newline before this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care of this!
} | ||
return err | ||
} | ||
if len(data) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just check if num > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken care of this!
Hi glinton, |
Closing in favor of #4773 |
Resolves #1483
This PR introduces a telegraf plugin to get docker logs . Sample output :
docker_log,containerId=4325333a47ab42c78b8bf5cb01d5b0972321f857a4b9e116856b4f0459047077,host=prash-laptop log=" root@4325333a47ab:/# ls -l\r\n" 1530162134000000000 docker_log,containerId=4325333a47ab42c78b8bf5cb01d5b0972321f857a4b9e116856b4f0459047077,host=prash-laptop log=" total 64\r\n drwxr-xr-x 2 root root 4096 May 26 00:45 bin\r\n drwxr-xr-x 2 root root 4096 Apr 24 08:34 boot\r\n drwxr-xr-x 5 root root 360 Jun 28 05:01 dev\r\n drwxr-xr-x 1 root root 4096 Jun 28 05:01 etc\r\n drwxr-xr-x 2 root root 4096 Apr 24 08:34 home\r\n drwxr-xr-x 8 root root 4096 May 26 00:44 lib\r\n drwxr-xr-x 2 root root 4096 May 26 00:44 lib64\r\n drwxr-xr-x 2 root root 4096 May 26 00:44 media\r\n drwxr-xr-x 2 root root 4096 May 26 00:44 mnt\r\n" 1530162134000000000
The plugin is a Telegraf service input plugin which creates a new goroutine for every running container and listens for the log stream using the docker engine APIs . Whenever it gets data from the stream it pushes it out with tags.
Required for all PRs: