summaryrefslogtreecommitdiffstats
path: root/src/endpoint
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-03-05 18:35:00 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-03-07 21:50:29 +0100
commitfe9f663353e516ca70ce6ffba1b587c3ced6c334 (patch)
tree498aa7110cf269d2c23a0987af7c57792303dbe0 /src/endpoint
parent3cadfc1e9a65d46c818d4209a0c4dde3aaed0032 (diff)
Add Endpoint::container_stats() with helper types
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/endpoint')
-rw-r--r--src/endpoint/configured.rs41
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 {