2024-02-17 03:48:29 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-12-22 21:54:41 +00:00
|
|
|
//go:build !linux
|
2015-08-05 10:19:36 -06:00
|
|
|
|
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2017-12-31 15:25:49 +09:00
|
|
|
"context"
|
2018-09-11 15:29:08 +08:00
|
|
|
|
2024-02-17 03:48:29 +00:00
|
|
|
"github.com/shirou/gopsutil/v4/internal/common"
|
2015-08-05 10:19:36 -06:00
|
|
|
)
|
2016-04-24 17:15:45 +09:00
|
|
|
|
|
|
|
// GetDockerStat returns a list of Docker basic stats.
|
|
|
|
// This requires certain permission.
|
|
|
|
func GetDockerStat() ([]CgroupDockerStat, error) {
|
2017-12-31 15:25:49 +09:00
|
|
|
return GetDockerStatWithContext(context.Background())
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetDockerStatWithContext(ctx context.Context) ([]CgroupDockerStat, error) {
|
2016-04-24 17:15:45 +09:00
|
|
|
return nil, ErrDockerNotAvailable
|
|
|
|
}
|
2015-08-05 10:19:36 -06:00
|
|
|
|
2022-01-30 22:48:09 +02:00
|
|
|
// GetDockerIDList returns a list of DockerID.
|
2015-08-05 10:19:36 -06:00
|
|
|
// This requires certain permission.
|
|
|
|
func GetDockerIDList() ([]string, error) {
|
2017-12-31 15:25:49 +09:00
|
|
|
return GetDockerIDListWithContext(context.Background())
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetDockerIDListWithContext(ctx context.Context) ([]string, error) {
|
2015-08-07 10:14:14 +09:00
|
|
|
return nil, ErrDockerNotAvailable
|
2015-08-05 10:19:36 -06:00
|
|
|
}
|
|
|
|
|
2022-01-30 22:48:09 +02:00
|
|
|
// CgroupCPU returns specified cgroup id CPU status.
|
2015-08-05 10:19:36 -06:00
|
|
|
// containerid is same as docker id if you use docker.
|
|
|
|
// If you use container via systemd.slice, you could use
|
|
|
|
// containerid = docker-<container id>.scope and base=/sys/fs/cgroup/cpuacct/system.slice/
|
2021-11-06 09:53:56 +00:00
|
|
|
func CgroupCPU(containerid string, base string) (*CgroupCPUStat, error) {
|
2017-12-31 15:25:49 +09:00
|
|
|
return CgroupCPUWithContext(context.Background(), containerid, base)
|
|
|
|
}
|
|
|
|
|
2021-11-06 09:53:56 +00:00
|
|
|
func CgroupCPUWithContext(ctx context.Context, containerid string, base string) (*CgroupCPUStat, error) {
|
2015-08-07 10:14:14 +09:00
|
|
|
return nil, ErrCgroupNotAvailable
|
2015-08-05 10:19:36 -06:00
|
|
|
}
|
|
|
|
|
2021-11-06 09:53:56 +00:00
|
|
|
func CgroupCPUDocker(containerid string) (*CgroupCPUStat, error) {
|
2017-12-31 15:25:49 +09:00
|
|
|
return CgroupCPUDockerWithContext(context.Background(), containerid)
|
|
|
|
}
|
|
|
|
|
2021-11-06 09:53:56 +00:00
|
|
|
func CgroupCPUDockerWithContext(ctx context.Context, containerid string) (*CgroupCPUStat, error) {
|
2023-06-03 14:17:16 -07:00
|
|
|
return CgroupCPUWithContext(ctx, containerid, common.HostSysWithContext(ctx, "fs/cgroup/cpuacct/docker"))
|
2015-08-05 10:19:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func CgroupMem(containerid string, base string) (*CgroupMemStat, error) {
|
2017-12-31 15:25:49 +09:00
|
|
|
return CgroupMemWithContext(context.Background(), containerid, base)
|
|
|
|
}
|
|
|
|
|
|
|
|
func CgroupMemWithContext(ctx context.Context, containerid string, base string) (*CgroupMemStat, error) {
|
2015-08-07 10:14:14 +09:00
|
|
|
return nil, ErrCgroupNotAvailable
|
2015-08-05 10:19:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func CgroupMemDocker(containerid string) (*CgroupMemStat, error) {
|
2017-12-31 15:25:49 +09:00
|
|
|
return CgroupMemDockerWithContext(context.Background(), containerid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func CgroupMemDockerWithContext(ctx context.Context, containerid string) (*CgroupMemStat, error) {
|
2023-05-26 15:57:41 -07:00
|
|
|
return CgroupMemWithContext(ctx, containerid, common.HostSysWithContext(ctx, "fs/cgroup/memory/docker"))
|
2015-08-05 10:19:36 -06:00
|
|
|
}
|