diff options
Diffstat (limited to 'src/endpoint/configured.rs')
-rw-r--r-- | src/endpoint/configured.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index 8685ec3..454850d 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -254,6 +254,24 @@ impl Endpoint { .map(EndpointStats::from) .map_err(Error::from) } + + pub async fn container_stats(&self) -> Result<Vec<ContainerStat>> { + self.docker + .containers() + .list({ + &shiplift::builder::ContainerListOptions::builder() + .all() + .build() + }) + .await + .map_err(Error::from) + .map(|containers| { + containers + .into_iter() + .map(ContainerStat::from) + .collect() + }) + } } /// Helper type to store endpoint statistics @@ -292,6 +310,29 @@ impl From<shiplift::rep::Info> for EndpointStats { } } +/// Helper type to store stats about a container +pub struct ContainerStat { + pub created: chrono::DateTime<chrono::Utc>, + pub id: String, + pub image: String, + pub image_id: String, + pub state: String, + pub status: String, +} + +impl From<shiplift::rep::Container> for ContainerStat { + fn from(cont: shiplift::rep::Container) -> Self { + ContainerStat { + created: cont.created, + id: cont.id, + image: cont.image, + image_id: cont.image_id, + state: cont.state, + status: cont.status, + } + } +} + pub struct EndpointHandle(Arc<Endpoint>); impl EndpointHandle { |