0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SystemInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 #ifndef Common_SystemInfo_h
27 #define Common_SystemInfo_h
28 
29 #include <Common/InetAddr.h>
30 #include <Common/Stopwatch.h>
31 #include <Common/System.h>
32 
33 #include <iosfwd>
34 #include <vector>
35 
36 namespace Hypertable {
37 
46  struct CpuInfo {
47  CpuInfo &init();
48  bool operator==(const CpuInfo &other) const;
49  bool operator!=(const CpuInfo &other) const {
50  return !(*this == other);
51  }
52 
55  int mhz;
56  uint32_t cache_size;
60  };
61 
66  struct CpuStat {
67  CpuStat &refresh();
68  bool operator==(const CpuStat &other) const;
69  bool operator!=(const CpuStat &other) const {
70  return !(*this == other);
71  }
72 
73  // system wide cpu time in percentage
74  double user;
75  double sys;
76  double nice;
77  double idle;
78  double wait;
79  double irq;
80  double soft_irq;
81  double stolen; // for virtualized env (Linux 2.6.11+)
82  double total;
83  };
84 
89  struct LoadAvgStat {
91  bool operator==(const LoadAvgStat &other) const;
92  bool operator!=(const LoadAvgStat &other) const {
93  return !(*this == other);
94  }
95 
96  double loadavg[3];
97  };
98 
103  struct MemStat {
104  MemStat &refresh();
105  bool operator==(const MemStat &other) const;
106  bool operator!=(const MemStat &other) const {
107  return !(*this == other);
108  }
109 
110  // memory usage in MB
111  double ram;
112  double total;
113  double used;
114  double free;
115  double actual_used; // excluding kernel buffers/caches
116  double actual_free; // including kernel buffers/caches
117  };
118 
123  struct DiskStat {
124  DiskStat() { }
125  DiskStat(const DiskStat &other);
126  ~DiskStat();
127  void swap (DiskStat &other);
128  DiskStat &refresh(const char *dir_prefix = "/");
129  DiskStat &operator=(const DiskStat &other) {
130  DiskStat tmp(other);
131  swap(tmp);
132  return *this;
133  }
134  bool operator==(const DiskStat &other) const;
135  bool operator!=(const DiskStat &other) const {
136  return !(*this == other);
137  }
138 
140  // aggregate io ops rate
141  double reads_rate {};
142  double writes_rate {};
143 
144  // aggreate transfer rate in bytes/s
145  double read_rate {};
146  double write_rate {};
147 
148  void *prev_stat {};
150  };
151 
156  struct SwapStat {
157  SwapStat() : prev_stat(0) { }
158  SwapStat(const SwapStat &other);
159  ~SwapStat();
160  void swap (SwapStat &other);
161  SwapStat &refresh();
162  SwapStat &operator=(const SwapStat &other) {
163  SwapStat tmp(other);
164  swap(tmp);
165  return *this;
166  }
167  bool operator==(const SwapStat &other) const;
168  bool operator!=(const SwapStat &other) const {
169  return !(*this == other);
170  }
171 
172  // aggregate in MB
173  double total {};
174  double used {};
175  double free {};
176 
177  uint64_t page_in {};
178  uint64_t page_out {};
179 
180  void *prev_stat {};
181  };
182 
187  struct NetInfo {
188  NetInfo &init();
189  bool operator==(const NetInfo &other) const;
190  bool operator!=(const NetInfo &other) const {
191  return !(*this == other);
192  }
193 
198  };
199 
204  struct NetStat {
205  NetStat &refresh();
206  bool operator==(const NetStat &other) const;
207  bool operator!=(const NetStat &other) const {
208  return !(*this == other);
209  }
210 
212  int32_t tcp_listen;
213  int32_t tcp_time_wait;
214  int32_t tcp_close_wait; // often indicating bugs
215  int32_t tcp_idle;
216 
217  // transfer rate in KB/s
218  double rx_rate; // receiving rate only primary interface for now
219  double tx_rate; // transmitting rate...
220  };
221 
226  struct OsInfo {
227  OsInfo &init();
228  bool operator==(const OsInfo &other) const;
229  bool operator!=(const OsInfo &other) const {
230  return !(*this == other);
231  }
232 
233  String name; // canonical system name
235  uint16_t version_major;
236  uint16_t version_minor;
237  uint16_t version_micro;
239  String machine; // more specific than arch (e.g. i686 vs i386)
246  };
247 
252  struct ProcInfo {
253  ProcInfo &init();
254  bool operator==(const ProcInfo &other) const;
255  bool operator!=(const ProcInfo &other) const {
256  return !(*this == other);
257  }
258 
259  int64_t pid;
264  std::vector<String> args;
265  };
266 
271  struct ProcStat {
272  ProcStat &refresh();
273  bool operator==(const ProcStat &other) const;
274  bool operator!=(const ProcStat &other) const {
275  return !(*this == other);
276  }
277 
278  // proc cpu time in ms
279  uint64_t cpu_user;
280  uint64_t cpu_sys;
281  uint64_t cpu_total;
282  double cpu_pct;
283 
284  // proc (virtual) memory usage in MB
285  double vm_size;
286  double vm_resident;
287  double vm_share;
288  uint64_t minor_faults;
289  uint64_t major_faults;
290  uint64_t page_faults;
291  uint64_t heap_size;
292  uint64_t heap_slack;
293  };
294 
299  struct FsStat {
300  FsStat() : use_pct(0.0), total(0), free(0),
301  used(0), avail(0), files(0), free_files(0) { }
302 
303  FsStat &refresh(const char *prefix = "/");
304  bool operator==(const FsStat &other) const;
305  bool operator!=(const FsStat &other) const {
306  return !(*this == other);
307  }
308 
309  // aggregate file system usage in GB
311  double use_pct;
312  uint64_t total;
313  uint64_t free;
314  uint64_t used;
315  uint64_t avail; // available to non-root users
316 
317  // aggregate files/inodes
318  uint64_t files;
319  uint64_t free_files; // free inodes
320  };
321 
325  struct TermInfo {
326  TermInfo &init();
327  bool operator==(const TermInfo &other) const;
328  bool operator!=(const TermInfo &other) const {
329  return !(*this == other);
330  }
331 
334  int num_cols;
335  };
336 
338  std::ostream &operator<<(std::ostream &, const CpuInfo &);
339 
341  std::ostream &operator<<(std::ostream &, const CpuStat &);
342 
344  std::ostream &operator<<(std::ostream &, const MemStat &);
345 
347  std::ostream &operator<<(std::ostream &, const DiskStat &);
348 
350  std::ostream &operator<<(std::ostream &, const OsInfo &);
351 
353  std::ostream &operator<<(std::ostream &, const SwapStat &);
354 
356  std::ostream &operator<<(std::ostream &, const NetInfo &);
357 
359  std::ostream &operator<<(std::ostream &, const NetStat &);
360 
362  std::ostream &operator<<(std::ostream &, const ProcInfo &);
363 
365  std::ostream &operator<<(std::ostream &, const ProcStat &);
366 
368  std::ostream &operator<<(std::ostream &, const FsStat &);
369 
371  std::ostream &operator<<(std::ostream &, const TermInfo &);
372 
374  const char *system_info_lib_version();
375 
378 }
379 
380 #endif // Common_SystemInfo_h
Retrieves system information (hardware, installation directory, etc)
void swap(SwapStat &other)
Definition: SystemInfo.cc:559
int32_t tcp_established
Definition: SystemInfo.h:211
bool operator==(const ProcStat &other) const
Definition: SystemInfo.cc:169
bool operator!=(const DiskStat &other) const
Definition: SystemInfo.h:135
uint16_t version_major
Definition: SystemInfo.h:235
bool operator==(const MemStat &other) const
Definition: SystemInfo.cc:88
NetInfo & init()
Definition: SystemInfo.cc:620
A structure to retrieve Swapping statistics (pages swapped in/out, aggregate total numbers etc) ...
Definition: SystemInfo.h:156
bool operator==(const ProcInfo &other) const
Definition: SystemInfo.cc:158
void swap(DiskStat &other)
Definition: SystemInfo.cc:501
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
The Stopwatch measures elapsed time.
bool operator==(const NetInfo &other) const
Definition: SystemInfo.cc:119
bool operator==(const OsInfo &other) const
Definition: SystemInfo.cc:140
uint16_t version_micro
Definition: SystemInfo.h:237
bool operator!=(const CpuInfo &other) const
Definition: SystemInfo.h:49
uint64_t free_files
Definition: SystemInfo.h:319
A structure to retrieve CPU statistics (system wide cpu times, idle time etc).
Definition: SystemInfo.h:66
bool operator!=(const LoadAvgStat &other) const
Definition: SystemInfo.h:92
bool operator==(const CpuInfo &other) const
Definition: SystemInfo.cc:54
DiskStat & operator=(const DiskStat &other)
Definition: SystemInfo.h:129
A structure to retrieve disk statistics (read/write IOPS, transfer rates etc)
Definition: SystemInfo.h:123
NetStat & refresh()
Definition: SystemInfo.cc:656
bool operator!=(const ProcStat &other) const
Definition: SystemInfo.h:274
bool operator==(const LoadAvgStat &other) const
Definition: SystemInfo.cc:80
CpuStat & refresh()
Definition: SystemInfo.cc:419
MemStat & refresh()
Definition: SystemInfo.cc:470
bool operator!=(const OsInfo &other) const
Definition: SystemInfo.h:229
bool operator!=(const MemStat &other) const
Definition: SystemInfo.h:106
A structure to retrieve terminal information (lines, columns etc)
Definition: SystemInfo.h:325
bool operator!=(const FsStat &other) const
Definition: SystemInfo.h:305
FsStat & refresh(const char *prefix="/")
Definition: SystemInfo.cc:782
LoadAvgStat & refresh()
Definition: SystemInfo.cc:458
bool operator==(const NetStat &other) const
Definition: SystemInfo.cc:128
int32_t tcp_close_wait
Definition: SystemInfo.h:214
A structure to retrieve CPU information (vendor, model, speed, number of cores etc.)
Definition: SystemInfo.h:46
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
bool operator==(const DiskStat &other) const
Definition: SystemInfo.cc:99
DiskStat & refresh(const char *dir_prefix="/")
Definition: SystemInfo.cc:511
A structure to receive process statistics (CPU user time, system time, virtmal machine sizes etc) ...
Definition: SystemInfo.h:271
bool operator!=(const NetStat &other) const
Definition: SystemInfo.h:207
A structure to retrieve memory statistics (RAM size, used size, free size etc)
Definition: SystemInfo.h:103
Hypertable definitions
SwapStat & operator=(const SwapStat &other)
Definition: SystemInfo.h:162
std::vector< String > args
Definition: SystemInfo.h:264
bool operator!=(const TermInfo &other) const
Definition: SystemInfo.h:328
A structure to retrieve network information (host name, primary interface, primary address...
Definition: SystemInfo.h:187
bool operator==(const CpuStat &other) const
Definition: SystemInfo.cc:66
A structure to retrieve Filesystem statistics (total size, free size, used size etc) ...
Definition: SystemInfo.h:299
A structure to retrieve load average-statistics.
Definition: SystemInfo.h:89
bool operator!=(const NetInfo &other) const
Definition: SystemInfo.h:190
uint32_t cache_size
Definition: SystemInfo.h:56
bool operator==(const TermInfo &other) const
Definition: SystemInfo.cc:199
const char * system_info_lib_version()
Returns a descriptive string of the libsigar version.
Definition: SystemInfo.cc:816
ProcInfo & init()
Definition: SystemInfo.cc:720
Internet address wrapper classes and utility functions.
bool operator!=(const ProcInfo &other) const
Definition: SystemInfo.h:255
The Stopwatch class measures elapsed time between instantiation (or a call to start) and a call to st...
Definition: Stopwatch.h:40
bool operator==(const SwapStat &other) const
Definition: SystemInfo.cc:109
CpuInfo & init()
Definition: SystemInfo.cc:399
bool operator!=(const CpuStat &other) const
Definition: SystemInfo.h:69
SwapStat & refresh()
Definition: SystemInfo.cc:568
ProcStat & refresh()
Definition: SystemInfo.cc:749
A structure to receive process information (pid, user name, exe name, working directory, program arguments etc)
Definition: SystemInfo.h:252
bool operator==(const FsStat &other) const
Definition: SystemInfo.cc:186
A structure to retrieve operating system information (name, version, vendor, architecture) ...
Definition: SystemInfo.h:226
uint16_t version_minor
Definition: SystemInfo.h:236
bool operator!=(const SwapStat &other) const
Definition: SystemInfo.h:168
TermInfo & init()
Definition: SystemInfo.cc:799
A structure to retrieve network statistics (receiving rate, transmitting rate etc) ...
Definition: SystemInfo.h:204