Commit 8786aad3 authored by Crystal Chua's avatar Crystal Chua
Browse files

adding quarkdb-health redis command, currently displays free space left

parent 4d4b5510
Pipeline #369208 passed with stages
in 16 minutes and 43 seconds
......@@ -97,6 +97,7 @@ struct cmdMapInit {
redis_cmd_map["activate_stale_reads"] = {RedisCommand::ACTIVATE_STALE_READS, CommandType::RAFT};
redis_cmd_map["quarkdb_info"] = {RedisCommand::QUARKDB_INFO, CommandType::QUARKDB};
redis_cmd_map["quarkdb_health"] = {RedisCommand::QUARKDB_HEALTH, CommandType::QUARKDB};
redis_cmd_map["quarkdb_detach"] = {RedisCommand::QUARKDB_DETACH, CommandType::QUARKDB};
redis_cmd_map["quarkdb_attach"] = {RedisCommand::QUARKDB_ATTACH, CommandType::QUARKDB};
redis_cmd_map["quarkdb_start_resilvering"] = {RedisCommand::QUARKDB_START_RESILVERING, CommandType::QUARKDB};
......
......@@ -101,6 +101,7 @@ enum class RedisCommand {
ACTIVATE_STALE_READS,
QUARKDB_INFO,
QUARKDB_HEALTH,
QUARKDB_DETACH,
QUARKDB_ATTACH,
QUARKDB_START_RESILVERING,
......
......@@ -31,6 +31,7 @@
#include "utils/TimeFormatting.hh"
#include <sys/stat.h>
#include <sys/statvfs.h>
using namespace quarkdb;
......@@ -98,6 +99,9 @@ LinkStatus QuarkDBNode::dispatch(Connection *conn, RedisRequest &req) {
case RedisCommand::QUARKDB_INFO: {
return conn->statusVector(this->info().toVector());
}
case RedisCommand::QUARKDB_HEALTH: {
return conn->statusVector(this->health().toVector());
}
default: {
return shard->dispatch(conn, req);
}
......@@ -119,3 +123,22 @@ std::vector<std::string> QuarkDBInfo::toVector() const {
ret.emplace_back(SSTR("UPTIME " << uptime << " (" << formatTime(std::chrono::seconds(uptime)) << ")"));
return ret;
}
QuarkDBHealth QuarkDBNode::health() {
struct statvfs buf;
// add some error checking pls
statvfs(configuration.getDatabase().c_str(), &buf);
double freeSpace = ((buf.f_bfree * 1.) / buf.f_blocks) * 100.;
return {freeSpace
};
}
std::vector<std::string> QuarkDBHealth::toVector() const {
std::vector<std::string> ret;
ret.emplace_back(SSTR("FREE-SPACE " << freeSpace << "%"));
ret.emplace_back(SSTR("RAFT-STABILITY placeholder"));
ret.emplace_back(SSTR("NODE-STATUS placeholder"));
return ret;
}
......@@ -44,6 +44,12 @@ struct QuarkDBInfo {
std::vector<std::string> toVector() const;
};
struct QuarkDBHealth {
double freeSpace;
std::vector<std::string> toVector() const;
};
class Shard; class ShardDirectory; class MultiOp;
class QuarkDBNode : public Dispatcher {
......@@ -70,6 +76,8 @@ private:
QuarkDBInfo info();
QuarkDBHealth health();
std::atomic<bool> shutdown {false};
const RaftTimeouts timeouts;
......
......@@ -74,7 +74,7 @@ bool verify_options_sane(option::Parser &parse, std::vector<option::Option> &opt
std::vector<option::Option> parse_args(int argc, char** argv) {
const option::Descriptor usage[] = {
{Opt::UNKNOWN, 0, "", "", option::Arg::None, "Tool to initialize new quarkdb nodes.\n"
"USAGE: quarkdb-journal [options]\n\n" "Options:" },
"USAGE: quarkdb-create [options]\n\n" "Options:" },
{Opt::HELP, 0, "", "help", option::Arg::None, " --help \tPrint usage and exit." },
{Opt::PATH, 0, "", "path", Opt::nonempty, " --path \tthe directory where the journal lives in."},
{Opt::CLUSTERID, 0, "", "clusterID", Opt::nonempty, " --clusterID \tspecify the identifier for the new cluster - should be globally unique."},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment