Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
DobbyStats.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2016 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19/*
20 * File: DobbyStats.h
21 *
22 */
23#ifndef DOBBYSTATS_H
24#define DOBBYSTATS_H
25
26#include <ContainerId.h>
27#include <IDobbyEnv.h>
28#include "IDobbyUtils.h"
29
30#include <memory>
31#include <string>
32
33#if defined(RDK)
34#include <json/json.h>
35#else
36#include <jsoncpp/json.h>
37#endif
38
39class IDobbyEnv;
40
41// -----------------------------------------------------------------------------
54{
55public:
56 DobbyStats(const ContainerId &id,
57 const std::shared_ptr<IDobbyEnv> &env,
58 const std::shared_ptr<IDobbyUtils> &utils);
60
61public:
62 const Json::Value &stats() const;
63
64private:
65 typedef struct Process
66 {
67 const pid_t pid;
68 const pid_t nsPid;
69 const std::string fileName;
70 const std::string cmdline;
71
72 inline void Serialise(Json::Value &root)
73 {
74 root["pid"] = pid;
75 root["nsPid"] = nsPid;
76 root["executable"] = fileName;
77 root["cmdline"] = cmdline;
78 }
79 } Process;
80
81private:
82 static ssize_t readCgroupFile(const ContainerId &id,
83 const std::string &cgroupMntPath,
84 const std::string &cgroupfileName,
85 char *buf, size_t bufLen);
86
87 static Json::Value readSingleCgroupValue(const ContainerId &id,
88 const std::string &cgroupMntPath,
89 const std::string &cgroupfileName);
90
91 static std::vector<int64_t> readMultipleCgroupValues(const ContainerId &id,
92 const std::string &cgroupMntPath,
93 const std::string &cgroupfileName);
94
95 static Json::Value readMultipleCgroupValuesJson(const ContainerId &id,
96 const std::string &cgroupMntPath,
97 const std::string &cgroupfileName);
98
99 static Json::Value getStats(const ContainerId &id,
100 const std::shared_ptr<IDobbyEnv> &env,
101 const std::shared_ptr<IDobbyUtils> &utils);
102
103 static Json::Value getProcessTree(const ContainerId &id,
104 const std::string &cpuCgroupMntPath,
105 const std::shared_ptr<IDobbyUtils> &utils);
106
107#if defined(RDK)
108 static Json::Value readIonCgroupHeaps(const ContainerId &id,
109 const std::string &ionCgroupPath);
110#endif
111
112 static Process getProcessInfo(pid_t pid,
113 const std::shared_ptr<IDobbyUtils> &utils);
114
115 static pid_t readNsPidFromProc(pid_t pid);
116
117private:
118 const Json::Value mStats;
119};
120
121#endif // !defined(DOBBYSTATS_H)
A wrapper around a std::string, used to add some type definition to to an id and also to sanity check...
Definition ContainerId.h:41
Small utility class used to get the stats of a container.
Definition DobbyStats.h:54
static pid_t readNsPidFromProc(pid_t pid)
Given a pid (in global namespace) tries to find what it's namespace pid is.
Definition DobbyStats.cpp:522
static Process getProcessInfo(pid_t pid, const std::shared_ptr< IDobbyUtils > &utils)
Returns information about a given PID.
Definition DobbyStats.cpp:469
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.
Definition DobbyStats.cpp:275
static Json::Value readSingleCgroupValue(const ContainerId &id, const std::string &cgroupMntPath, const std::string &cgroupfileName)
Reads a single value from the given cgroup file.
Definition DobbyStats.cpp:319
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.
Definition DobbyStats.cpp:363
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.
Definition DobbyStats.cpp:436
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.
Definition DobbyStats.cpp:110
Interface that exports the environment of the daemon to plugins.
Definition IDobbyEnv.h:46
Definition DobbyStats.h:66