faradayio / boondock

Docker daemon API in Rust
43 stars 14 forks source link

How to inspect stats when a kernel feature is disabled? #28

Open gcavalcante8808 opened 6 years ago

gcavalcante8808 commented 6 years ago

Hi Folks,

In these days, much of the linux kernels running doesnt have the Cgroup Swap support activated and because of this, there is no field called 'swap' for the container stats. When I try to gather some container stats with the following code

    for container in &containers {
        let _stats = match docker.stats(container) {
            Ok(stats) => stats,
            Err(e) => { panic!("{}", e); }
        };

        for stat in _stats{
            println!("{:?}", stat);
        }
    }

It returns to me the message "(Some(Error("missing field swap", line: 1, column: 4183)), None)))".

Thanks in advance.

fussybeaver commented 6 years ago

Take a look at https://github.com/faradayio/boondock/pull/20 , perhaps that fixes the error..

gcavalcante8808 commented 6 years ago

Yeah, I can confirm that. In my case, the following changes on structs fixed the problem:

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Stats {
    pub read: String,
    pub network: Option<Network>,
    pub memory_stats: MemoryStats,
    pub cpu_stats: CpuStats,
    pub blkio_stats: BlkioStats
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryStat {
    pub total_pgmajfault: u64,
    pub cache: u64,
    pub mapped_file: u64,
    pub total_inactive_file: u64,
    pub pgpgout: u64,
    pub rss: u64,
    pub total_mapped_file: u64,
    pub writeback: u64,
    pub unevictable: u64,
    pub pgpgin: u64,
    pub total_unevictable: u64,
    pub pgmajfault: u64,
    pub total_rss: u64,
    pub total_rss_huge: u64,
    pub total_writeback: u64,
    pub total_inactive_anon: u64,
    pub rss_huge: u64,
    pub hierarchical_memory_limit: u64,
    pub hierarchical_memsw_limit: u64,
    pub total_pgfault: u64,
    pub total_active_file: u64,
    pub active_anon: u64,
    pub total_active_anon: u64,
    pub total_pgpgout: u64,
    pub total_cache: u64,
    pub inactive_anon: u64,
    pub active_file: u64,
    pub pgfault: u64,
    pub inactive_file: u64,
    pub total_pgpgin: u64,
    pub swap: Option<u64>,
    pub total_swap: Option<u64>
}

As I can see, there is no conflicts on the https://github.com/faradayio/boondock/pull/20 PR. Is there any plans to merge it?

emk commented 6 years ago

Thank you for figuring this out!

Please see my note on this PR about the maintenance schedule for boondock: https://github.com/faradayio/boondock/pull/21. TL;dr: I've been juggling other stuff lately, but I hope to get back around to it soon.