0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
System.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_System_h
27 #define Common_System_h
28 
30 #include <Common/String.h>
31 #include <Common/Version.h>
32 
33 #include <ctime>
34 #include <memory>
35 #include <mutex>
36 
37 namespace Hypertable {
38 
43  struct CpuInfo;
44  struct CpuStat;
45  struct LoadAvgStat;
46  struct MemStat;
47  struct DiskStat;
48  struct OsInfo;
49  struct SwapStat;
50  struct NetInfo;
51  struct NetStat;
52  struct ProcInfo;
53  struct ProcStat;
54  struct FsStat;
55  struct TermInfo;
56 
60  class System {
61  public:
72  static inline void initialize(const String &install_directory = String()) {
73  std::lock_guard<std::mutex> lock(ms_mutex);
74 
75  if (ms_initialized)
76  return;
77 
78  // Set timezone
79  tzset();
80 
81 #if !defined(__sun__)
82  // Set timezone variables
83  {
84  struct tm tmbuf;
85  time_t now = time(0);
86  localtime_r(&now, &tmbuf);
87  tm_gmtoff = tmbuf.tm_gmtoff;
88  tm_zone = String(tmbuf.tm_zone);
89  }
90 #endif
91 
92  check_version();
93  _init(install_directory);
94  ms_initialized = true;
95  }
96 
97 
103  static String locate_install_dir(const char *argv0);
104 
111  static String _locate_install_dir(const char *argv0);
112 
115 
117  static std::unique_ptr<ClusterDefinition::ClusterDefinition> cluster_def;
118 
120  static String exe_name;
121 
123  static long tm_gmtoff;
124 
126  static String tm_zone;
127 
129  static void initialize_tm(struct tm *tmval);
130 
132  static int32_t get_processor_count();
133 
135  static int32_t get_pid();
136 
138  static int32_t get_drive_count();
139 
141  static const CpuInfo &cpu_info();
142 
144  static const CpuStat &cpu_stat();
145 
147  static const MemStat &mem_stat();
148 
150  static const DiskStat &disk_stat();
151 
153  static const OsInfo &os_info();
154 
156  static const SwapStat &swap_stat();
157 
159  static const NetInfo &net_info();
160 
162  static const NetStat &net_stat();
163 
165  static const ProcInfo &proc_info();
166 
168  static const ProcStat &proc_stat();
169 
171  static const FsStat &fs_stat();
172 
174  static const TermInfo &term_info();
175 
177  static const LoadAvgStat &loadavg_stat();
178 
179  private:
181  static void _init(const String &install_directory);
182 
184  static bool ms_initialized;
185 
188 
189  };
190 
193 }
194 
195 #endif // Common_System_h
static std::mutex mutex
Definition: Logger.cc:43
static const NetStat & net_stat()
Retrieves updated Network statistics (see SystemInfo.h)
Definition: SystemInfo.cc:369
static const CpuInfo & cpu_info()
Retrieves updated CPU information (see SystemInfo.h)
Definition: SystemInfo.cc:322
A structure to retrieve Swapping statistics (pages swapped in/out, aggregate total numbers etc) ...
Definition: SystemInfo.h:156
static bool ms_initialized
true if initialize was already called
Definition: System.h:184
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
static const CpuStat & cpu_stat()
Retrieves updated CPU statistics (see SystemInfo.h)
Definition: SystemInfo.cc:331
static String tm_zone
Timezone abbreviation.
Definition: System.h:126
static void initialize(const String &install_directory=String())
Initializes the static class members; checks header version vs.
Definition: System.h:72
A structure to retrieve CPU statistics (system wide cpu times, idle time etc).
Definition: SystemInfo.h:66
static const ProcInfo & proc_info()
Retrieves updated Process information (see SystemInfo.h)
Definition: SystemInfo.cc:373
static const ProcStat & proc_stat()
Retrieves updated Process statistics (see SystemInfo.h)
Definition: SystemInfo.cc:382
A structure to retrieve disk statistics (read/write IOPS, transfer rates etc)
Definition: SystemInfo.h:123
static void initialize_tm(struct tm *tmval)
Initialize struct tm.
Definition: System.cc:94
static int32_t get_processor_count()
The processor count.
Definition: System.cc:103
static const LoadAvgStat & loadavg_stat()
Retrieves updated Load average statistics (see SystemInfo.h)
Definition: SystemInfo.cc:335
static const DiskStat & disk_stat()
Retrieves updated Disk statistics (see SystemInfo.h)
Definition: SystemInfo.cc:343
static long tm_gmtoff
Seconds east of UTC.
Definition: System.h:123
A structure to retrieve terminal information (lines, columns etc)
Definition: SystemInfo.h:325
static String exe_name
The exe file name.
Definition: System.h:120
static const OsInfo & os_info()
Retrieves updated Operating system information (see SystemInfo.h)
Definition: SystemInfo.cc:347
A structure to retrieve CPU information (vendor, model, speed, number of cores etc.)
Definition: SystemInfo.h:46
Declarations for ClusterDefinition.
A structure to receive process statistics (CPU user time, system time, virtmal machine sizes etc) ...
Definition: SystemInfo.h:271
static int32_t get_drive_count()
Returns the number of drives.
Definition: System.cc:111
static std::mutex ms_mutex
a Mutex to protect the static members
Definition: System.h:187
A structure to retrieve memory statistics (RAM size, used size, free size etc)
Definition: SystemInfo.h:103
static const SwapStat & swap_stat()
Retrieves updated Swap statistics (see SystemInfo.h)
Definition: SystemInfo.cc:356
static const FsStat & fs_stat()
Retrieves updated Filesystem statistics (see SystemInfo.h)
Definition: SystemInfo.cc:386
Hypertable definitions
static String locate_install_dir(const char *argv0)
Returns the installation directory.
Definition: System.cc:50
A structure to retrieve network information (host name, primary interface, primary address...
Definition: SystemInfo.h:187
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
static String install_dir
The installation directory.
Definition: System.h:114
A String class based on std::string.
static void _init(const String &install_directory)
Internal initialization helper.
Definition: System.cc:73
static std::unique_ptr< ClusterDefinition::ClusterDefinition > cluster_def
Cluster definition.
Definition: System.h:117
static const TermInfo & term_info()
Retrieves updated Terminal information (see SystemInfo.h)
Definition: SystemInfo.cc:390
static int32_t get_pid()
The pid of the current process.
Definition: System.cc:132
A structure to receive process information (pid, user name, exe name, working directory, program arguments etc)
Definition: SystemInfo.h:252
static const MemStat & mem_stat()
Retrieves updated Memory statistics (see SystemInfo.h)
Definition: SystemInfo.cc:339
static const NetInfo & net_info()
Retrieves updated Network information (see SystemInfo.h)
Definition: SystemInfo.cc:360
static String _locate_install_dir(const char *argv0)
Returns the installation directory; same as locate_install_dir but does not lock ms_mutex.
Definition: System.cc:55
A structure to retrieve operating system information (name, version, vendor, architecture) ...
Definition: SystemInfo.h:226
A structure to retrieve network statistics (receiving rate, transmitting rate etc) ...
Definition: SystemInfo.h:204