0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
system_info.cc
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 
27 #include <Common/Compat.h>
28 #include <Common/Init.h>
29 #include <Common/SystemInfo.h>
30 
31 using namespace std;
32 using namespace Hypertable;
33 using namespace Config;
34 
35 namespace {
36 
37 struct MyPolicy : Policy {
38  static void init_options() {
39  cmdline_desc().add_options()
40  ("my-ip", "Display the primary IP Address of the host")
41  ("install-dir", "Display install directory")
42  ("property,p", strs(), "Display the value of the specified property")
43  ;
44  }
45 };
46 
47 typedef Meta::list<MyPolicy, DefaultPolicy> Policies;
48 
49 void dump_all() {
50  cout << system_info_lib_version() << endl;
51  cout << System::cpu_info() << endl;
52  cout << System::cpu_stat() << endl;
53  cout << System::mem_stat() << endl;
54  cout << System::disk_stat() << endl;
55  cout << System::os_info() << endl;
56  cout << System::swap_stat() << endl;
57  cout << System::net_info() << endl;
58  cout << System::net_stat() << endl;
59  cout << System::proc_info() << endl;
60  cout << System::proc_stat() << endl;
61  cout << System::fs_stat() << endl;
62  cout << System::term_info() << endl;
63  cout << "{System: install_dir='" << System::install_dir
64  << "' exe_name='" << System::exe_name << "'}" << endl;
65 }
66 
67 } // local namespace
68 
69 int main(int ac, char *av[]) {
70  init_with_policies<Policies>(ac, av);
71  bool has_option = false;
72 
73  if (has("my-ip")) {
74  cout << System::net_info().primary_addr << endl;
75  has_option = true;
76  }
77  if (has("install-dir")) {
78  cout << System::install_dir << endl;
79  has_option = true;
80  }
81  if (has("property")) {
82  Strings strs = get_strs("property");
83 
84  for (auto &s : strs)
85  cout << Properties::to_str((*properties)[s]) << endl;
86 
87  has_option = true;
88  }
89  if (!has_option)
90  dump_all();
91 }
Interface and base of config policy.
Definition: Config.h:149
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
std::vector< String > Strings
Definition: Properties.h:148
STL namespace.
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
Definition: Config.cc:72
bool has(const String &name)
Check existence of a configuration value.
Definition: Config.h:57
Compatibility Macros for C/C++.
Initialization helper for applications.
int main(int ac, char *av[])
Definition: system_info.cc:69
Po::typed_value< Strings > * strs(Strings *v=0)
Definition: Properties.h:170
Hypertable definitions
const char * system_info_lib_version()
Returns a descriptive string of the libsigar version.
Definition: SystemInfo.cc:816
Meta::list< MyPolicy, DefaultPolicy > Policies
System information and statistics based on libsigar.