mirror of https://github.com/Icinga/icinga2.git
cluster: Periodically clean up old log files.
This commit is contained in:
parent
fe0fb171d0
commit
4be2105584
|
@ -29,6 +29,7 @@
|
||||||
#include "base/convert.h"
|
#include "base/convert.h"
|
||||||
#include <boost/smart_ptr/make_shared.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <boost/exception/diagnostic_information.hpp>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
@ -312,9 +313,7 @@ void ClusterComponent::ReplayLog(const Endpoint::Ptr& endpoint, const Stream::Pt
|
||||||
std::sort(files.begin(), files.end());
|
std::sort(files.begin(), files.end());
|
||||||
|
|
||||||
BOOST_FOREACH(int ts, files) {
|
BOOST_FOREACH(int ts, files) {
|
||||||
std::ostringstream msgbuf;
|
String path = GetClusterDir() + Convert::ToString(ts);
|
||||||
msgbuf << GetClusterDir() << ts;
|
|
||||||
String path = msgbuf.str();
|
|
||||||
|
|
||||||
if (ts < endpoint->GetLocalLogPosition())
|
if (ts < endpoint->GetLocalLogPosition())
|
||||||
continue;
|
continue;
|
||||||
|
@ -424,8 +423,38 @@ void ClusterComponent::ClusterTimerHandler(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
Log(LogInformation, "cluster", "Attempting to reconnect to cluster endpoint '" + endpoint->GetName() + "' via '" + host + ":" + port + "'.");
|
Log(LogInformation, "cluster", "Attempting to reconnect to cluster endpoint '" + endpoint->GetName() + "' via '" + host + ":" + port + "'.");
|
||||||
AddConnection(host, port);
|
AddConnection(host, port);
|
||||||
|
} catch (std::exception& ex) {
|
||||||
|
std::ostringstream msgbuf;
|
||||||
|
msgbuf << "Exception occured while reconnecting to endpoint '"
|
||||||
|
<< endpoint->GetName() << "': " << boost::diagnostic_information(ex);
|
||||||
|
Log(LogWarning, "cluster", msgbuf.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int> files;
|
||||||
|
Utility::Glob(GetClusterDir() + "*", boost::bind(&ClusterComponent::LogGlobHandler, boost::ref(files), _1));
|
||||||
|
std::sort(files.begin(), files.end());
|
||||||
|
|
||||||
|
BOOST_FOREACH(int ts, files) {
|
||||||
|
bool need = false;
|
||||||
|
|
||||||
|
BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
|
||||||
|
double position = endpoint->GetLocalLogPosition();
|
||||||
|
|
||||||
|
if (position != 0 && ts > position) {
|
||||||
|
need = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!need) {
|
||||||
|
String path = GetClusterDir() + Convert::ToString(ts);
|
||||||
|
Log(LogInformation, "cluster", "Removing old log file: " + path);
|
||||||
|
(void) unlink(path.CStr());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -348,9 +348,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "Exception occured during notification for service '"
|
msgbuf << "Exception occured during notification for service '"
|
||||||
<< GetService()->GetName() << "': " << boost::diagnostic_information(ex);
|
<< GetService()->GetName() << "': " << boost::diagnostic_information(ex);
|
||||||
String message = msgbuf.str();
|
Log(LogWarning, "icinga", msgbuf.str());
|
||||||
|
|
||||||
Log(LogWarning, "icinga", message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue