artdaq_utilities  v1_05_00
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 {
9 {
10 public:
11  SystemMetricCollector(bool processMetrics, bool systemMetrics);
12 
13  double GetSystemCPUUsagePercent();
14  double GetProcessCPUUsagePercent();
15 
16  unsigned long GetAvailableRAM();
17  unsigned long GetBufferedRAM();
18  unsigned long GetTotalRAM();
19  double GetAvailableRAMPercent(bool buffers);
20  unsigned long GetProcessMemUsage();
21  double GetProcessMemUsagePercent();
22 
23  unsigned long GetNetworkReceiveBytes();
24  unsigned long GetNetworkSendBytes();
25  unsigned long GetNetworkReceiveErrors();
26  unsigned long GetNetworkSendErrors();
27 
28  std::list<std::unique_ptr<MetricData>> SendMetrics();
29 
30 private:
31  struct cpustat
32  {
33  unsigned long long user, nice, system, idle, iowait, irq, softirq;
34  unsigned long long totalUsage, total;
35  cpustat()
36  : user(0), nice(0), system(0), idle(0), iowait(0), irq(0), softirq(0), totalUsage(0), total(0) {}
37  };
38  cpustat ReadProcStat_();
39 
40  struct netstat
41  {
42  unsigned long long send_bytes, recv_bytes, send_errs, recv_errs;
43  std::chrono::steady_clock::time_point collectionTime;
44  netstat()
45  : send_bytes(0), recv_bytes(0), send_errs(0), recv_errs(0) {}
46  };
47  netstat ReadProcNetDev_();
48  void UpdateNetstat_();
49 
50  cpustat lastCPU_;
51  struct tms lastProcessCPUTimes_;
52  clock_t lastProcessCPUTime_;
53  netstat thisNetStat_;
54  netstat lastNetStat_;
55  bool sendProcessMetrics_;
56  bool sendSystemMetrics_;
57 };
58 } // namespace artdaq