Add OS info, which now just contains the os version.

Change-Id: Ifdaf80702301ff6beb3fd34abe814fd2fa904607
Reviewed-on: http://gerrit.ent.cloudera.com:8080/619
Tested-by: jenkins
Reviewed-by: Nong Li <nong@cloudera.com>
This commit is contained in:
Nong Li
2013-10-06 16:31:46 -07:00
committed by Henry Robinson
parent 49c07abce3
commit c868350fbd
5 changed files with 99 additions and 0 deletions

View File

@@ -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());

View File

@@ -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

48
be/src/util/os-info.cc Normal file
View File

@@ -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 <iostream>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
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();
}
}

42
be/src/util/os-info.h Normal file
View File

@@ -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 <string>
#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

View File

@@ -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) << "</pre>";
(*output) << "<h2>OS Info</h2>";
(*output) << "<pre>";
(*output) << OsInfo::DebugString();
(*output) << "</pre>";
(*output) << "<h2>Status Pages</h2>";
BOOST_FOREACH(const PathHandlerMap::value_type& handler, path_handlers_) {