hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCEResourceExtractor.hpp
Go to the documentation of this file.
1 
15 #ifndef DRCE_RESOURCE_EXTRACTOR_HPP
16 #define DRCE_RESOURCE_EXTRACTOR_HPP
17 
18 #include <iostream>
19 #include <utility>
20 #include <Poco/Exception.h>
21 #include <Poco/Mutex.h>
22 #include <Poco/ScopedLock.h>
23 
24 #include "DRCEResourceUsage.hpp"
25 
26 namespace HCE
27 {
28 namespace drce
29 {
30 //-----------------------------------------------------------------------------
32 {
33 public:
34  DiskSpaceExtractor(void);
36 
37  void update(void) throw (Poco::Exception);
38 
39  void setDiskSize(size_t diskSize_);
40 
41  size_t getDiskSize(void) const {return diskSize;}
42  size_t getDiskUsed(void) const {return diskUsed;}
43  size_t getDiskFree(void) const {return diskFree;}
44  double getDiskUsedPercent(void) const {return diskUsedPercent;}
45  double getDiskFreePercent(void) const {return diskFreePercent;}
46 
47  static size_t getDiskUsage(const std::vector<pid_t>& ids);
48 private:
49  static size_t getDiskUsageBytes(pid_t pid);
50  static size_t getFileSize(const std::string& filename);
51 private:
52  size_t diskSize;
53  size_t diskUsed;
54  size_t diskFree;
55  double diskUsedPercent;
56  double diskFreePercent;
57 
58  size_t externalDiskSize;
59 };
60 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 {
64  struct cpu_info {
65  unsigned long long user;
66  unsigned long long system;
67  unsigned long long idle;
68  unsigned long long iowait;
69  } newCpu, oldCpu;
70  const unsigned int SLPTIME = 1000000; //200000;
71 public:
72  CpuUsageExtractor(void);
74 
75  void update(void);
76 
77  double getCpuUsage(void) const {return cpuUsage;}
78  double getIOWait(void) const {return iowait;}
79 
80  static double getCpuUsage(const std::vector<pid_t>& ids);
81 private:
82  void updateUsage(void);
83 
84  double cpuUsage;
85 // unsigned long long lastBusy;
86 // unsigned long long lastWork;
87 
88  double iowait;
89 // unsigned long long lastIOWait;
90 // unsigned long long lastSum;
91 
92  static void getCpuData(pid_t pid, std::pair<unsigned long int, unsigned long int>& p);
93 };
94 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
97 {
98  enum {SZ=3};
99 public:
100  LoadAverageExtractor(void);
102 
103  void update(void);
104 
105  double getLoadAverage(unsigned int index);
106 private:
107  double loadAverage[SZ]={0.0};
108 };
109 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
112 {
113 public:
114  struct MemInfo
115  {
116  MemInfo(void);
117  MemInfo(MemInfo&& rhs);
118  MemInfo& operator=(MemInfo&& rhs);
119 
120  size_t memTotal;
121  size_t memFree;
122  size_t buffers;
123  size_t cached;
124  size_t swapTotal;
125  size_t swapFree;
126  size_t vmallocTotal;
127  size_t vmallocUsed;
128  };
129 
130  MemoryExtractor(void);
132 
133  void update(void);
134 
135  size_t getVramUsed(void) const {return vramUsed;}
136  size_t getRramUsed(void) const {return rramUsed;}
137  size_t getVramFree(void) const {return vramFree;}
138  size_t getRramFree(void) const {return rramFree;}
139 
140  double getVramUsedPercent(void) const {return vramUsedPercent;}
141  double getRramUsedPercent(void) const {return rramUsedPercent;}
142  double getVramFreePercent(void) const {return vramFreePercent;}
143  double getRramFreePercent(void) const {return rramFreePercent;}
144 
145  size_t getVramTotal(void) const {return vramTotal;}
146  size_t getRramTotal(void) const {return rramTotal;}
147 
148  void setVramTotal(size_t vramTotal_);
149  void setRramTotal(size_t rramTotal_);
150 private:
151  static MemInfo getMemoryInfo(void);
152 private:
153  size_t vramUsed;
154  size_t rramUsed;
155  size_t vramFree;
156  size_t rramFree;
157  double vramUsedPercent;
158  double rramUsedPercent;
159  double vramFreePercent;
160  double rramFreePercent;
161 
162  size_t vramTotal;
163  size_t rramTotal;
164 
165  size_t externalVramTotal;
166  size_t externalRramTotal;
167 };
168 //-----------------------------------------------------------------------------
169 //-----------------------------------------------------------------------------
170 class AsyncTasks;
172 {
173 public:
174  struct FieldsArray
175  {
176  FieldsArray(void);
177  FieldsArray(const FieldsArray& rhs);
178  FieldsArray(FieldsArray&& rhs);
179 
180  FieldsArray& operator=(const FieldsArray& rhs);
182 
183  void clear(void);
184 
185  double cpu;
186  size_t vram;
187  size_t rram;
188  size_t threads;
189  size_t disk;
190  };
191 
194 
195  static FieldsArray extract(const AsyncTasks& asyncTask);
196 };
197 //-----------------------------------------------------------------------------
198 //-----------------------------------------------------------------------------
200 {
201 public:
202  static ResourceUsageExtractor& getInstance(void);
203  static void shutdown(void);
204 
205  void update(void);
206  ResourceUsage extract(void) throw (Poco::Exception);
207 
212 
213  void setMaxThreadsCount(size_t maxThreadsCount_);
214  size_t getMaxThreadsCount(void);
215 
216  void setMaxProcessesCount(size_t maxProcessesCount_);
217  size_t getMaxProcessesCount(void);
218 
219  void setMaxDiskSize(size_t maxDiskSize_);
220  size_t getMaxDiskSize(void);
221 
222  void setMaxVramSize(size_t maxVramSize_);
223  size_t getMaxVramSize(void);
224 
225  void setMaxRramSize(size_t maxRramSize_);
226  size_t getMaxRramSize(void);
227 
228 protected:
230  static Poco::Mutex mutex;
231 
236 
239 private:
241  ~ResourceUsageExtractor(void) {};
244 };
245 //-----------------------------------------------------------------------------
246 //-----------------------------------------------------------------------------
247 } // end namespace drce
248 } // end namespace HCE
249 
250 #endif // DRCE_RESOURCE_EXTRACTOR_HPP