diff --git a/be/src/common/init.cc b/be/src/common/init.cc index 1de33ae70..9b050091d 100644 --- a/be/src/common/init.cc +++ b/be/src/common/init.cc @@ -21,6 +21,7 @@ #include "util/logging-support.h" #include "util/mem-info.h" #include "util/network-util.h" +#include "util/os-info.h" #include "rpc/thrift-util.h" #include "util/thread.h" @@ -43,10 +44,12 @@ void impala::InitCommonRuntime(int argc, char** argv, bool init_jvm) { CpuInfo::Init(); DiskInfo::Init(); MemInfo::Init(); + OsInfo::Init(); LOG(INFO) << CpuInfo::DebugString(); LOG(INFO) << DiskInfo::DebugString(); LOG(INFO) << MemInfo::DebugString(); + LOG(INFO) << OsInfo::DebugString(); if (init_jvm) { EXIT_IF_ERROR(JniUtil::Init()); diff --git a/be/src/util/CMakeLists.txt b/be/src/util/CMakeLists.txt index 25580b366..207e52d4c 100644 --- a/be/src/util/CMakeLists.txt +++ b/be/src/util/CMakeLists.txt @@ -45,6 +45,7 @@ add_library(Util mem-info.cc metrics.cc network-util.cc + os-info.cc parse-util.cc path-builder.cc periodic-counter-updater diff --git a/be/src/util/os-info.cc b/be/src/util/os-info.cc new file mode 100644 index 000000000..9417a978f --- /dev/null +++ b/be/src/util/os-info.cc @@ -0,0 +1,48 @@ +// Copyright 2012 Cloudera Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "util/os-info.h" + +#include +#include +#include +#include +#include + +#include + +using namespace std; + +namespace impala { + +bool OsInfo::initialized_ = false; +string OsInfo::os_version_ = "Unknown"; + +void OsInfo::Init() { + DCHECK(!initialized_); + // Read from /proc/version + ifstream version("/proc/version", ios::in); + if (version.good()) getline(version, os_version_); + if (version.is_open()) version.close(); + initialized_ = true; +} + +string OsInfo::DebugString() { + DCHECK(initialized_); + stringstream stream; + stream << "OS version: " << os_version_ << endl; + return stream.str(); +} + +} diff --git a/be/src/util/os-info.h b/be/src/util/os-info.h new file mode 100644 index 000000000..1344467d3 --- /dev/null +++ b/be/src/util/os-info.h @@ -0,0 +1,42 @@ +// Copyright 2012 Cloudera Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef IMPALA_UTIL_OS_INFO_H +#define IMPALA_UTIL_OS_INFO_H + +#include +#include "common/logging.h" + +namespace impala { + +// Provides information about the OS we're running on. +class OsInfo { + public: + // Initialize OsInfo. + static void Init(); + + static const std::string os_version() { + DCHECK(initialized_); + return os_version_; + } + + static std::string DebugString(); + + private: + static bool initialized_; + static std::string os_version_; +}; + +} +#endif diff --git a/be/src/util/webserver.cc b/be/src/util/webserver.cc index 349a546c6..f1a2f50dd 100644 --- a/be/src/util/webserver.cc +++ b/be/src/util/webserver.cc @@ -29,6 +29,7 @@ #include "util/cpu-info.h" #include "util/disk-info.h" #include "util/mem-info.h" +#include "util/os-info.h" #include "util/url-coding.h" #include "util/logging.h" #include "util/debug-util.h" @@ -108,6 +109,10 @@ void Webserver::RootHandler(const Webserver::ArgumentMap& args, stringstream* ou (*output) << MemInfo::DebugString(); (*output) << DiskInfo::DebugString(); (*output) << ""; + (*output) << "

OS Info

"; + (*output) << "
";
+  (*output) << OsInfo::DebugString();
+  (*output) << "
"; (*output) << "

Status Pages

"; BOOST_FOREACH(const PathHandlerMap::value_type& handler, path_handlers_) {