pub struct StatsCommand {
pub executor: CommandExecutor,
/* private fields */
}
Expand description
Docker stats command builder
Display a live stream of container(s) resource usage statistics.
§Example
use docker_wrapper::StatsCommand;
// Get stats for all running containers
let stats = StatsCommand::new()
.run()
.await?;
// Get stats for specific containers
let stats = StatsCommand::new()
.container("my-container")
.container("another-container")
.no_stream()
.run()
.await?;
// Parse as JSON for programmatic use
let json_stats = StatsCommand::new()
.format("json")
.no_stream()
.run()
.await?;
Fields§
§executor: CommandExecutor
Command executor
Implementations§
Source§impl StatsCommand
impl StatsCommand
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new stats command
§Example
use docker_wrapper::StatsCommand;
let cmd = StatsCommand::new();
Sourcepub fn container(self, container: impl Into<String>) -> Self
pub fn container(self, container: impl Into<String>) -> Self
Add a container to monitor
§Example
use docker_wrapper::StatsCommand;
let cmd = StatsCommand::new()
.container("web-server")
.container("database");
Sourcepub fn containers(self, containers: Vec<impl Into<String>>) -> Self
pub fn containers(self, containers: Vec<impl Into<String>>) -> Self
Add multiple containers to monitor
Sourcepub fn all(self) -> Self
pub fn all(self) -> Self
Show stats for all containers (default shows only running)
§Example
use docker_wrapper::StatsCommand;
let cmd = StatsCommand::new().all();
Sourcepub fn format(self, format: impl Into<String>) -> Self
pub fn format(self, format: impl Into<String>) -> Self
Set output format
§Example
use docker_wrapper::StatsCommand;
// JSON format for programmatic parsing
let cmd = StatsCommand::new().format("json");
// Table format (default)
let cmd = StatsCommand::new().format("table");
Sourcepub fn no_stream(self) -> Self
pub fn no_stream(self) -> Self
Disable streaming stats and only pull the first result
§Example
use docker_wrapper::StatsCommand;
let cmd = StatsCommand::new().no_stream();
Sourcepub async fn run(&self) -> Result<StatsResult>
pub async fn run(&self) -> Result<StatsResult>
Execute the stats command
§Errors
Returns an error if:
- The Docker daemon is not running
- Any specified container doesn’t exist
- No containers are running (when no specific containers are specified)
§Example
use docker_wrapper::StatsCommand;
let result = StatsCommand::new()
.container("my-container")
.no_stream()
.run()
.await?;
if result.success() {
println!("Container stats:\n{}", result.output.stdout);
}
Trait Implementations§
Source§impl Clone for StatsCommand
impl Clone for StatsCommand
Source§fn clone(&self) -> StatsCommand
fn clone(&self) -> StatsCommand
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for StatsCommand
impl Debug for StatsCommand
Source§impl Default for StatsCommand
impl Default for StatsCommand
Source§impl DockerCommand for StatsCommand
impl DockerCommand for StatsCommand
Source§type Output = CommandOutput
type Output = CommandOutput
The output type this command produces
Source§fn get_executor(&self) -> &CommandExecutor
fn get_executor(&self) -> &CommandExecutor
Get the command executor for extensibility
Source§fn get_executor_mut(&mut self) -> &mut CommandExecutor
fn get_executor_mut(&mut self) -> &mut CommandExecutor
Get mutable command executor for extensibility
Source§fn build_command_args(&self) -> Vec<String>
fn build_command_args(&self) -> Vec<String>
Build the complete command arguments including subcommands
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute the command and return the typed output
Source§fn execute_command<'life0, 'async_trait>(
&'life0 self,
command_args: Vec<String>,
) -> Pin<Box<dyn Future<Output = Result<CommandOutput>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn execute_command<'life0, 'async_trait>(
&'life0 self,
command_args: Vec<String>,
) -> Pin<Box<dyn Future<Output = Result<CommandOutput>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
Helper method to execute the command with proper error handling
Source§fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self
fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self
Add a raw argument to the command (escape hatch)
Auto Trait Implementations§
impl Freeze for StatsCommand
impl RefUnwindSafe for StatsCommand
impl Send for StatsCommand
impl Sync for StatsCommand
impl Unpin for StatsCommand
impl UnwindSafe for StatsCommand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more