From 161dbe6b8c479128f3092e8b7c3449c39be27986 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 5 Mar 2021 16:17:09 +0100 Subject: Add Endpoint::stats() and helper type for gathering statistics Signed-off-by: Matthias Beyer --- src/endpoint/configured.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/endpoint/configured.rs') diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index 68e6e60..8685ec3 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -246,6 +246,50 @@ impl Endpoint { pub async fn ping(&self) -> Result { self.docker.ping().await.map_err(Error::from) } + + pub async fn stats(&self) -> Result { + self.docker + .info() + .await + .map(EndpointStats::from) + .map_err(Error::from) + } +} + +/// Helper type to store endpoint statistics +/// +/// Currently, this can only be generated from a shiplift::rep::Info, but it does not hold all +/// values the shiplift::rep::Info type holds, because some of these are not relevant for us. +/// +/// Later, this might hold endpoint stats from other endpoint implementations as well +pub struct EndpointStats { + pub name: String, + pub containers: u64, + pub images: u64, + pub id: String, + pub kernel_version: String, + pub mem_total: u64, + pub memory_limit: bool, + pub n_cpu: u64, + pub operating_system: String, + pub system_time: Option, +} + +impl From for EndpointStats { + fn from(info: shiplift::rep::Info) -> Self { + EndpointStats { + name: info.name, + containers: info.containers, + images: info.images, + id: info.id, + kernel_version: info.kernel_version, + mem_total: info.mem_total, + memory_limit: info.memory_limit, + n_cpu: info.n_cpu, + operating_system: info.operating_system, + system_time: info.system_time, + } + } } pub struct EndpointHandle(Arc); -- cgit v1.2.3