|
static ssize_t | readCgroupFile (const ContainerId &id, const std::string &cgroupMntPath, const std::string &cgroupfileName, char *buf, size_t bufLen) |
| Reads a maximum of 4096 bytes from the given cgroup file.
|
|
static Json::Value | readSingleCgroupValue (const ContainerId &id, const std::string &cgroupMntPath, const std::string &cgroupfileName) |
| Reads a single value from the given cgroup file.
|
|
static std::vector< int64_t > | readMultipleCgroupValues (const ContainerId &id, const std::string &cgroupMntPath, const std::string &cgroupfileName) |
| Reads multiple values from the given cgroup file.
|
|
static Json::Value | readMultipleCgroupValuesJson (const ContainerId &id, const std::string &cgroupMntPath, const std::string &cgroupfileName) |
|
static Json::Value | getStats (const ContainerId &id, const std::shared_ptr< IDobbyEnv > &env, const std::shared_ptr< IDobbyUtils > &utils) |
| Gets the stats for the container.
|
|
static Json::Value | getProcessTree (const ContainerId &id, const std::string &cpuCgroupMntPath, const std::shared_ptr< IDobbyUtils > &utils) |
| Builds a json array of the processes running in the container.
|
|
static Process | getProcessInfo (pid_t pid, const std::shared_ptr< IDobbyUtils > &utils) |
| Returns information about a given PID.
|
|
static pid_t | readNsPidFromProc (pid_t pid) |
| Given a pid (in global namespace) tries to find what it's namespace pid is.
|
|
Small utility class used to get the stats of a container.
There is not much to this class, it's just a collection of utility functions for gathering statistics on a container with a given id.
Note that the code in this class tends not to print errors if it can't gather some stats, that's by design as it's meant to be a best effort.
Json::Value DobbyStats::getProcessTree |
( |
const ContainerId & |
id, |
|
|
const std::string & |
cpuCgroupMntPath, |
|
|
const std::shared_ptr< IDobbyUtils > & |
utils |
|
) |
| |
|
staticprivate |
Builds a json array of the processes running in the container.
Will return a json array with all the processes inside the container with their filename, cmdline and PID (both in the host and container namespace)
"processes": [ { "pid": "2345", "nsPid": "1" "file": "/usr/libexec/DobbyInit", "cmdline": "/usr/libexec/DobbyInit sleep 30", } ]
- Parameters
-
[in] | id | The string id of the container. |
- Returns
- Json array with all container processes
Gets the stats for the container.
This is primarily a debugging method, used to get statistics on the container and roughly correlates to the 'runc events –stats <id>' call.
The reply is a json formatted string containing some info, it's form may change over time.
{
"timestamp": 348134887768,
"pids": [ 2046, 2064 ],
"cpu": {
"usage": {
"total":734236982,
"percpu":[348134887,386102095]
}
},
"memory":{
"user": {
"limit":41943040,
"usage":356352,
"max":524288,
"failcnt":0
}
}
"gpu":{
"memory": {
"limit":41943040,
"usage":356352,
"max":524288,
"failcnt":0
}
}
...
}
- Parameters
-
[in] | id | The container id, assumed to also be the name of the cgroups. |
[in] | env | The environment setup, used to get the mount point(s) of the various cgroups. |
- Returns
- The populated json stats, may be an empty object if no cgroups could be found.
std::vector< int64_t > DobbyStats::readMultipleCgroupValues |
( |
const ContainerId & |
id, |
|
|
const std::string & |
cgroupMntPath, |
|
|
const std::string & |
cgroupfileName |
|
) |
| |
|
staticprivate |
Reads multiple values from the given cgroup file.
The path to read is made up like:
<cgroupMntPath>/<id>/<cgroupfileName>
Each value is expected to be delimited with either a space, tab or newline.
- Parameters
-
[in] | id | The string id of the container. |
[in] | cgroupMntPath | The path to the cgroup mount point. |
[in] | cgroupfileName | The name of the cgroup file. |
- Returns
- The value read as a json object, typically an integer value.