private async Task <SwarmInformation> GetSwarmInformationAsync(IDockerClients clients) { var ping = await clients.SystemClient.PingAsync(); var diskUsage = await clients.SystemClient.GetDiskUsageAsync(); var version = await clients.SystemClient.GetSystemVersionAsync(); var containers = await clients.ContainerClient.GetContainersAsync(); var tasks = await clients.TaskClient.GetTasksAsync(); var nodes = await clients.NodeClient.GetNodesAsync(); var swarmServices = await clients.ServiceClient.GetServicesAsync(); var swarm = new SwarmInformation { DiskUsage = diskUsage, LocalContainers = containers, Ping = ping, SwarmNodes = nodes, SwarmServices = swarmServices, SwarmTasks = tasks, SystemVersion = version }; return(swarm); }
public async Task OnEventOccurred(IDockerClients clients, IServiceProvider serviceProvider, Message message) { using (this._logger.BeginScope("{@event}", message)) { this._logger.LogInformation("Event occurred"); try { var swarm = await this.GetSwarmInformationAsync(clients); var tasks = new List <Task>(); var targets = this.FilterTargets(this._options.CurrentValue.Targets, message); foreach (var target in this._options.CurrentValue.Targets) { tasks.Add(this.ProcessTarget(target, swarm)); } await Task.WhenAll(tasks); } catch (Exception exception) { this._logger.LogCritical(exception, "Unhandled exception while processing events! {@options}", this._options.CurrentValue); } } }