diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-03-05 16:17:09 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-03-07 21:50:29 +0100 |
commit | 161dbe6b8c479128f3092e8b7c3449c39be27986 (patch) | |
tree | 5ced39b6dbd3a9f4ffb89cc0b6f244ed6a5127ff /src | |
parent | 61fb91fe4a4e0302b97aff777e68a98d15989da0 (diff) |
Add Endpoint::stats() and helper type for gathering statistics
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/endpoint/configured.rs | 44 |
1 files changed, 44 insertions, 0 deletions
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<String> { self.docker.ping().await.map_err(Error::from) } + + pub async fn stats(&self) -> Result<EndpointStats> { + 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<String>, +} + +impl From<shiplift::rep::Info> 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<Endpoint>); |