dotnet / Docker.DotNet

:whale: .NET (C#) Client Library for Docker API
https://www.nuget.org/packages/Docker.DotNet/
MIT License
2.23k stars 381 forks source link

MonitorEventsAsync syntax for --since param #650

Closed dazinator closed 1 year ago

dazinator commented 1 year ago

I am trying to figure out how to use the await _dockerClient.System.MonitorEventsAsync( api and specify a since parameter. Multiple variations have been unsuccessful.

    await _dockerClient.System.MonitorEventsAsync(
                    new ContainerEventsParameters()
                    {
                        Since ="",                        
                        Filters = new Dictionary<string, IDictionary<string, bool>>()
                        {
                            {
                                "type", new Dictionary<string,bool>()
                                {
                                    { "service", true }
                                }
                            }
                        }
                    }, new Progress<Message>(OnHandleServiceEvent), monitorCancelToken.Token);

What version of Docker.DotNet?:

3.125.15

When my application first runs, I'd like to get all the logs since the beginning of time. What should I specify as the since parameter to do this? All my attempts have resulted in a parse error returned from docker.

Then as I progress each log, it has a unix datetime associated with it. I am able to save an anchor locally based on var anchorDateTime = DateTimeOffset.FromUnixTimeSeconds(message.Time); where message is the log message received via the above monitor events async api. if my application terminates, when it next runs, I load the anchor as a datetime. In this instances I want to get the logs greater than the last anchor date. I am aware that the docker api for this allows --since to be passed in various forms like unix timestamps or RFC3339 dates. I think I'd just like to find a successful exampe of this param being used and to understand what is supported so I can try and woork out how to fulfil this use case where I anchor by the message time.

HofmeisterAn commented 1 year ago

The container log API expects the since and until argument as total seconds starting on the January 1st 1970 at UTC (Unix epoch). We are passing the following to the Docker endpoint 1 and 2. I hope that helps.

dazinator commented 1 year ago

Thanks yup that works. Looks like you can't use RFC3339 datetime.