Skip to content

Resolves #146: Registered new command for hostInfo #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ add_executable(fdbdoc
QLPredicate.h
QLTypes.cpp
QLTypes.h
version.cpp Constants.cpp Constants.h)
version.cpp Constants.cpp Constants.h HostInfo.cpp HostInfo.h)

set(ACTOR_FILES
BufferedConnection.actor.cpp
25 changes: 25 additions & 0 deletions src/ExtCmd.actor.cpp
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
#include "ExtMsg.actor.h"
#include "ExtUtil.actor.h"

#include "HostInfo.h"
#include "QLPlan.actor.h"
#include "QLProjection.actor.h"

@@ -498,6 +499,30 @@ struct RenameCollectionCmd {
};
REGISTER_CMD(RenameCollectionCmd, "renamecollection");

struct HostInfoCmd {
static const char* name;
static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> ec,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
diagnostics::HOSTINFO hostInfo;
bson::BSONObj systemInfo = hostInfo.getSystemInfo();
bson::BSONObj osInfo = hostInfo.getOsInfo();
bson::BSONObj extraInfo = hostInfo.getExtraInfo();
try {
if (!systemInfo.isEmpty() || !osInfo.isEmpty() || !extraInfo.isEmpty()) {
reply->addDocument(
BSON("system" << systemInfo << "os" << osInfo << "extra" << extraInfo << "ok" << 1.0));
} else {
throw unable_to_fetch_the_hostinfo();
}
} catch (Error& e) {
reply->addDocument(BSON("$err" << e.what() << "code" << e.code() << "ok" << 1.0));
}
return Future<Reference<ExtMsgReply>>(reply);
}
};
REGISTER_CMD(HostInfoCmd, "hostinfo");

ACTOR static Future<Reference<ExtMsgReply>> getStreamCount(Reference<ExtConnection> ec,
Reference<ExtMsgQuery> query,
Reference<ExtMsgReply> reply) {
545 changes: 545 additions & 0 deletions src/HostInfo.cpp

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions src/HostInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* HostInfo.h
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
*
* 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.
*/

#pragma once

#include "bson.h"

namespace diagnostics {
class HOSTINFO {
public:
HOSTINFO() {}
~HOSTINFO() {}

// returns bson object with physical system information
bson::BSONObj getSystemInfo();

// returns bson object with Operating System information
bson::BSONObj getOsInfo();

// returns bson object with CPU,kernel related information
bson::BSONObj getExtraInfo();

private:
// returns 64 or 32 bit machine
int getCpuAddressSize();
// returns total memory of machine
int getMemSizeMB();
// returns total number of CPU cores in this machine
int getNumCores();
// returns system supports NUMA or not
bool checkNumaEnabled();
// returns kernel version
std::string getVersionString();
// returns supported features of this CPU
std::string getCpuFeatures();
#if defined(__linux__)
// returns matching string value from given path
std::string readFromFile(std::string findName, std::string delimiter, std::string filePath);
// returns a line from a file
std::string readLineFromFile(const char* fileName);
// returns OS name and version
void getOsRelease(std::string& osName, std::string& osVersion);
// returns linux kernel version and upstream version
std::string getVersionSignature();
// returns dynamic cpu frequency
std::string getCpuFrequencyMHZ();
// returns version of glibc
std::string getLibcVersion();
// returns number of pages of physical memory
int getNumPages();
// returns maximum number of files a process can open
int getMaxOpenFiles();
// returns size of a page in bytes
long long getPageSize();
// returns cgroup memory limit
long long getMemLimitMB();
#elif defined(__APPLE__)
// returns kernel information of Mac OS in string format
std::string getSysctlByName(const char* sysctlName);
// returns kernel information of Mac OS in long long format
long long getSysctlByValue(const char* sysctlName);
// returns OS version
std::string getOsRelease();
// returns VFS related information
int getAlwaysFullSync();
int getNfsAsync();
// returns Mac Model number
std::string getModel();
// returns physical core count
int getPhysicalCores();
// returns dynamic cpu frequency
int getCpuFrequencyMHZ();
// returns CPU information
std::string getCpuString();
// returns size of a page in bytes
int getPageSize();
// returns OS scheduler information
std::string getScheduler();
#endif
};
} // namespace diagnostics
1 change: 1 addition & 0 deletions src/error_definitions.h
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ DOCLAYER_ERROR(multiple_index_construction, 20004, "tried to create multiple ind
DOCLAYER_ERROR(unique_index_background_construction, 20005, "tried to create unique indexes in background");
DOCLAYER_ERROR(empty_set_on_insert, 20009, "$setOnInsert is empty");
DOCLAYER_ERROR(cant_modify_id, 20010, "You may not modify '_id' in an update");
DOCLAYER_ERROR(unable_to_fetch_the_hostinfo, 20011, "Unable to fetch the HostInfo");

DOCLAYER_ERROR(update_operator_empty_parameter,
26840,
2 changes: 1 addition & 1 deletion thirdparty/bson-cpp/bson.h
Original file line number Diff line number Diff line change
@@ -40,4 +40,4 @@
#include "bsonobjbuilder.h"
#include "bsonobjiterator.h"
#include "bson-inl.h"
#include "bson_db.h"
#include "bson_db.h"