Monitoring  3.3.4
O2 Monitoring library
ProcessMonitor.h
Go to the documentation of this file.
1 // Copyright CERN and copyright holders of ALICE O2. This software is
2 // distributed under the terms of the GNU General Public License v3 (GPL
3 // Version 3), copied verbatim in the file "COPYING".
4 //
5 // See http://alice-o2.web.cern.ch/license for full licensing information.
6 //
7 // In applying this license CERN does not waive the privileges and immunities
8 // granted to it by virtue of its status as an Intergovernmental Organization
9 // or submit itself to any jurisdiction.
10 
15 
16 #ifndef ALICEO2_MONITORING_CORE_PROCESSMONITOR_H
17 #define ALICEO2_MONITORING_CORE_PROCESSMONITOR_H
18 
19 #include <atomic>
20 #include <boost/algorithm/string.hpp>
21 #include <iostream>
22 #include <string>
23 #include <vector>
24 #include <sys/resource.h>
25 
26 #include "Monitoring/Metric.h"
27 
28 namespace o2
29 {
31 namespace monitoring
32 {
33 
36 {
37  friend class Monitoring;
38 
39  public:
40  enum {
41  MEMORY_USAGE_PERCENTAGE = 0,
42  VIRTUAL_MEMORY_SIZE,
43  RESIDENT_SET_SIZE,
44  CPU_USED_PERCENTAGE,
45  INVOLUNTARY_CONTEXT_SWITCHING,
46  CPU_USED_ABSOLUTE,
47  AVG_RESIDENT_SET_SIZE,
48  AVG_VIRTUAL_MEMORY_SIZE,
49  AVG_CPU_USED_PERCENTAGE,
50  ACCUMULATED_CPU_TIME,
51  PSS,
52  AVAILABLE_METRICS_SIZE
53  };
54 
55  static std::vector<std::string> getAvailableMetricsNames();
56  std::vector<Metric> getPerformanceMetrics();
57 
58  public:
61 
63  ~ProcessMonitor() = default;
64 
65  void init();
66 
67  private:
68  double splitStatusLineAndRetriveValue(const std::string& line) const;
69 
71  void setTotalMemory();
72 
73  private:
74  static constexpr const char* metricsNames[] = {"memoryUsagePercentage", "virtualMemorySize", "residentSetSize",
75  "cpuUsedPercentage", "involuntaryContextSwitches", "cpuUsedAbsolute",
76  "averageResidentSetSize", "averageVirtualMemorySize", "averageCpuUsedPercentage",
77  "cpuTimeConsumedByProcess", "proportionalSetSize"};
78 
79  static constexpr unsigned int VM_SIZE_INDEX = 18;
80  static constexpr unsigned int VM_RSS_INDEX = 22;
81 
83  unsigned int mPid;
84 
86  unsigned int mTotalMemory;
87 
89  struct rusage mPreviousGetrUsage;
90 
92  std::vector<double> mVmSizeMeasurements;
93  std::vector<double> mVmRssMeasurements;
94  std::vector<uint64_t> mCpuMicroSeconds;
95  std::vector<double> mCpuPerctange;
96 
98  std::chrono::high_resolution_clock::time_point mTimeLastRun;
99 
101  std::vector<Metric> getMemoryUsage();
102 
104  Metric getPss();
105 
107  std::vector<Metric> getCpuAndContexts();
108 
109  std::vector<Metric> makeLastMeasurementAndGetMetrics();
110 };
111 
112 } // namespace monitoring
113 } // namespace o2
114 
115 #endif // ALICEO2_MONITORING_CORE_PROCESSMONITOR_H
Definition: Backend.h:23
Monitors current process and/or other processes running at the same machien.
Definition: ProcessMonitor.h:35
ProcessMonitor()
Prepares externam software commands (ps)
Definition: ProcessMonitor.cxx:22
Main class that collects metrics from user and dispatches them to selected monitoring backends...
Definition: Monitoring.h:46
Represents a metric including value, type of the value, name, timestamp and tags. ...
Definition: Metric.h:37
~ProcessMonitor()=default
Default destructor.