2015-08-06 00:19:36 +08:00
|
|
|
package docker
|
|
|
|
|
2016-05-20 16:59:41 +08:00
|
|
|
import (
|
2018-01-09 10:12:00 +08:00
|
|
|
"encoding/json"
|
2016-05-20 16:59:41 +08:00
|
|
|
"errors"
|
|
|
|
|
2021-11-06 17:53:56 +08:00
|
|
|
"github.com/shirou/gopsutil/v3/cpu"
|
|
|
|
"github.com/shirou/gopsutil/v3/internal/common"
|
2016-05-20 16:59:41 +08:00
|
|
|
)
|
2015-08-06 00:19:36 +08:00
|
|
|
|
2021-12-23 05:54:41 +08:00
|
|
|
var (
|
|
|
|
ErrDockerNotAvailable = errors.New("docker not available")
|
|
|
|
ErrCgroupNotAvailable = errors.New("cgroup not available")
|
|
|
|
)
|
2015-08-06 00:19:36 +08:00
|
|
|
|
2018-03-21 22:08:39 +08:00
|
|
|
var invoke common.Invoker = common.Invoke{}
|
2016-05-20 16:59:41 +08:00
|
|
|
|
2018-09-21 11:18:13 +08:00
|
|
|
const nanoseconds = 1e9
|
|
|
|
|
2018-09-11 15:29:08 +08:00
|
|
|
type CgroupCPUStat struct {
|
|
|
|
cpu.TimesStat
|
|
|
|
Usage float64
|
|
|
|
}
|
|
|
|
|
2015-08-06 00:19:36 +08:00
|
|
|
type CgroupMemStat struct {
|
2016-03-23 09:52:46 +08:00
|
|
|
ContainerID string `json:"containerID"`
|
2015-08-06 00:19:36 +08:00
|
|
|
Cache uint64 `json:"cache"`
|
|
|
|
RSS uint64 `json:"rss"`
|
2016-03-23 09:52:46 +08:00
|
|
|
RSSHuge uint64 `json:"rssHuge"`
|
|
|
|
MappedFile uint64 `json:"mappedFile"`
|
2015-08-06 00:19:36 +08:00
|
|
|
Pgpgin uint64 `json:"pgpgin"`
|
|
|
|
Pgpgout uint64 `json:"pgpgout"`
|
|
|
|
Pgfault uint64 `json:"pgfault"`
|
|
|
|
Pgmajfault uint64 `json:"pgmajfault"`
|
2016-03-23 09:52:46 +08:00
|
|
|
InactiveAnon uint64 `json:"inactiveAnon"`
|
|
|
|
ActiveAnon uint64 `json:"activeAnon"`
|
|
|
|
InactiveFile uint64 `json:"inactiveFile"`
|
|
|
|
ActiveFile uint64 `json:"activeFile"`
|
2015-08-06 00:19:36 +08:00
|
|
|
Unevictable uint64 `json:"unevictable"`
|
2016-03-23 09:52:46 +08:00
|
|
|
HierarchicalMemoryLimit uint64 `json:"hierarchicalMemoryLimit"`
|
|
|
|
TotalCache uint64 `json:"totalCache"`
|
|
|
|
TotalRSS uint64 `json:"totalRss"`
|
|
|
|
TotalRSSHuge uint64 `json:"totalRssHuge"`
|
|
|
|
TotalMappedFile uint64 `json:"totalMappedFile"`
|
|
|
|
TotalPgpgIn uint64 `json:"totalPgpgin"`
|
|
|
|
TotalPgpgOut uint64 `json:"totalPgpgout"`
|
|
|
|
TotalPgFault uint64 `json:"totalPgfault"`
|
|
|
|
TotalPgMajFault uint64 `json:"totalPgmajfault"`
|
|
|
|
TotalInactiveAnon uint64 `json:"totalInactiveAnon"`
|
|
|
|
TotalActiveAnon uint64 `json:"totalActiveAnon"`
|
|
|
|
TotalInactiveFile uint64 `json:"totalInactiveFile"`
|
|
|
|
TotalActiveFile uint64 `json:"totalActiveFile"`
|
|
|
|
TotalUnevictable uint64 `json:"totalUnevictable"`
|
|
|
|
MemUsageInBytes uint64 `json:"memUsageInBytes"`
|
|
|
|
MemMaxUsageInBytes uint64 `json:"memMaxUsageInBytes"`
|
2021-11-06 17:53:56 +08:00
|
|
|
MemLimitInBytes uint64 `json:"memoryLimitInBytes"`
|
2016-03-23 09:52:46 +08:00
|
|
|
MemFailCnt uint64 `json:"memoryFailcnt"`
|
2015-08-06 00:19:36 +08:00
|
|
|
}
|
2016-04-24 16:15:45 +08:00
|
|
|
|
2018-01-09 10:12:00 +08:00
|
|
|
func (m CgroupMemStat) String() string {
|
|
|
|
s, _ := json.Marshal(m)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
2016-04-24 16:15:45 +08:00
|
|
|
type CgroupDockerStat struct {
|
|
|
|
ContainerID string `json:"containerID"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Image string `json:"image"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
Running bool `json:"running"`
|
|
|
|
}
|
2018-01-09 10:12:00 +08:00
|
|
|
|
|
|
|
func (c CgroupDockerStat) String() string {
|
|
|
|
s, _ := json.Marshal(c)
|
|
|
|
return string(s)
|
|
|
|
}
|