artdaq_utilities  v1_05_09
SystemMetricCollector.hh
1 #include <sys/times.h>
2 #include <list>
3 #include <memory>
4 #include <string>
5 #include "artdaq-utilities/Plugins/MetricData.hh"
6 
7 namespace artdaq {
12 {
13 public:
19  SystemMetricCollector(bool processMetrics, bool systemMetrics);
20 
25  double GetSystemCPUUsagePercent();
31 
36  uint64_t GetAvailableRAM();
41  uint64_t GetBufferedRAM();
46  uint64_t GetTotalRAM();
52  double GetAvailableRAMPercent(bool buffers);
57  uint64_t GetProcessMemUsage();
63 
68  uint64_t GetNetworkReceiveBytes();
73  uint64_t GetNetworkSendBytes();
78  uint64_t GetNetworkReceiveErrors();
83  uint64_t GetNetworkSendErrors();
84 
89  std::list<std::unique_ptr<MetricData>> SendMetrics();
90 
91 private:
92  struct cpustat
93  {
94  uint64_t user{0}, nice{0}, system{0}, idle{0}, iowait{0}, irq{0}, softirq{0};
95  uint64_t totalUsage{0}, total{0};
96  };
97  cpustat ReadProcStat_();
98 
99  struct netstat
100  {
101  uint64_t send_bytes{0}, recv_bytes{0}, send_errs{0}, recv_errs{0};
102  std::chrono::steady_clock::time_point collectionTime;
103  };
104  netstat ReadProcNetDev_();
105  void UpdateNetstat_();
106 
107  cpustat lastCPU_;
108  struct tms lastProcessCPUTimes_;
109  clock_t lastProcessCPUTime_;
110  netstat thisNetStat_;
111  netstat lastNetStat_;
112  bool sendProcessMetrics_;
113  bool sendSystemMetrics_;
114 };
115 } // namespace artdaq
uint64_t GetNetworkSendBytes()
Get the amount of data sent to the network in the last network collection interval (1...
uint64_t GetNetworkSendErrors()
Get the number of network send errors in the last network collection interval (1.0 s) ...
uint64_t GetNetworkReceiveBytes()
Get the amount of data received from the network in the last network collection interval (1...
uint64_t GetTotalRAM()
Get the total amount of RAM in the system
uint64_t GetProcessMemUsage()
Get the amount of RAM being used by this process
std::list< std::unique_ptr< MetricData > > SendMetrics()
Send the configured metrics
Collects metrics from the system, using proc filesystem or kernel API calls
double GetAvailableRAMPercent(bool buffers)
Get the percentage of available RAM
uint64_t GetAvailableRAM()
Get the amount of available RAM in the system
double GetProcessCPUUsagePercent()
Return the current amount of CPU usage for the current process, %
SystemMetricCollector(bool processMetrics, bool systemMetrics)
SystemMetricCollector Constructor
double GetProcessMemUsagePercent()
Get the amount of RAM being used by this process
double GetSystemCPUUsagePercent()
Return the current overall system CPU usage in %
uint64_t GetNetworkReceiveErrors()
Get the number of network receive errors in the last network collection interval (1.0 s)
uint64_t GetBufferedRAM()
Get the amount of RAM currently being used for cache