-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add LogMonitor to check the log disk is full
- Loading branch information
Showing
7 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) 2021 vesoft inc. All rights reserved. | ||
# | ||
# This source code is licensed under Apache 2.0 License. | ||
|
||
nebula_add_library( | ||
log_monitor_obj OBJECT | ||
LogMonitor.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
#include "common/log/LogMonitor.h" | ||
|
||
namespace nebula { | ||
|
||
DEFINE_uint64(log_min_reserved_bytes_to_warn, | ||
256 * (1UL << 20), | ||
"if freebytes in logdir less than this, will change log level to WARN"); | ||
DEFINE_uint64(log_min_reserved_bytes_to_error, | ||
64 * (1UL << 20), | ||
"if freebytes in logdir less than this, will change log level to ERROR"); | ||
DEFINE_uint64(log_min_reserved_bytes_to_fatal, | ||
4 * (1UL << 20), | ||
"if freebytes in logdir less than this, will change log level to FATAL"); | ||
DEFINE_int32(log_disk_check_interval_secs, 10, "interval to check free space of log path"); | ||
|
||
void LogMonitor::getLogDiskFreeByte() { | ||
boost::system::error_code ec; | ||
auto info = boost::filesystem::space(FLAGS_log_dir, ec); | ||
if (!ec) { | ||
freeByte_ = info.available; | ||
} else { | ||
LOG(WARNING) << "Get filesystem info of logdir: " << FLAGS_log_dir << " failed"; | ||
} | ||
} | ||
|
||
void LogMonitor::checkAndChangeLogLevel() { | ||
getLogDiskFreeByte(); | ||
|
||
if (freeByte_ < FLAGS_log_min_reserved_bytes_to_warn) { | ||
LOG(ERROR) << "log disk freebyte is less than " << FLAGS_log_min_reserved_bytes_to_warn | ||
<< ", change log level to WARNING"; | ||
FLAGS_minloglevel = google::GLOG_WARNING; | ||
} else if (freeByte_ < FLAGS_log_min_reserved_bytes_to_error) { | ||
LOG(ERROR) << "log disk freebyte is less than " << FLAGS_log_min_reserved_bytes_to_error | ||
<< ", change log level to ERROR"; | ||
FLAGS_minloglevel = google::GLOG_ERROR; | ||
} else if (freeByte_ < FLAGS_log_min_reserved_bytes_to_fatal) { | ||
LOG(ERROR) << "log disk freebyte is less than " << FLAGS_log_min_reserved_bytes_to_fatal | ||
<< ", change log level to FATAL"; | ||
FLAGS_minloglevel = google::GLOG_FATAL; | ||
} else { | ||
// if freeByte_ is bigger than every min_log_flag, reset the FLAGS_minloglevel to old value | ||
if (FLAGS_minloglevel != oldMinLogLevel_) { | ||
FLAGS_minloglevel = oldMinLogLevel_; | ||
} | ||
} | ||
} | ||
|
||
} // namespace nebula |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
#pragma once | ||
|
||
#include <boost/filesystem.hpp> | ||
#include <boost/system/error_code.hpp> | ||
|
||
#include "common/thread/GenericWorker.h" | ||
|
||
namespace nebula { | ||
|
||
DECLARE_uint64(log_min_reserved_bytes_to_warn); | ||
DECLARE_uint64(log_min_reserved_bytes_to_error); | ||
DECLARE_uint64(log_min_reserved_bytes_to_fatal); | ||
DECLARE_int32(log_disk_check_interval_secs); | ||
|
||
class LogMonitor { | ||
public: | ||
LogMonitor() : oldMinLogLevel_(FLAGS_minloglevel), freeByte_(1UL << 60) { | ||
worker_ = std::make_shared<thread::GenericWorker>(); | ||
CHECK(worker_->start()); | ||
worker_->addRepeatTask( | ||
FLAGS_log_disk_check_interval_secs * 1000, &LogMonitor::checkAndChangeLogLevel, this); | ||
} | ||
|
||
~LogMonitor() { | ||
worker_->stop(); | ||
worker_->wait(); | ||
} | ||
|
||
void getLogDiskFreeByte(); | ||
|
||
void checkAndChangeLogLevel(); | ||
|
||
private: | ||
int32_t oldMinLogLevel_; | ||
std::shared_ptr<thread::GenericWorker> worker_; | ||
std::atomic_uint64_t freeByte_; | ||
}; | ||
|
||
} // namespace nebula |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters