Skip to content

journald feature: log as many as mainlog #9597

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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion etc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ endif()

if(NOT WIN32)
install(CODE "file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled\")")
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/mainlog.conf \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled/mainlog.conf\")")

if(HAVE_SYSTEMD)
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/journald.conf \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled/journald.conf\")")
else()
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink ../features-available/mainlog.conf \"\$ENV{DESTDIR}${ICINGA2_FULL_CONFIGDIR}/features-enabled/mainlog.conf\")")
endif()

install(FILES bash_completion.d/icinga2 DESTINATION ${BASHCOMPLETION_DIR})
else()
Expand Down
2 changes: 1 addition & 1 deletion etc/icinga2/features-available/journald.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
*/

object JournaldLogger "journald" {
severity = "warning"
severity = "information"
}
6 changes: 3 additions & 3 deletions lib/base/workqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ using namespace icinga;
std::atomic<int> WorkQueue::m_NextID(1);
boost::thread_specific_ptr<WorkQueue *> l_ThreadWorkQueue;

WorkQueue::WorkQueue(size_t maxItems, int threadCount, LogSeverity statsLogLevel)
WorkQueue::WorkQueue(size_t maxItems, int threadCount)
: m_ID(m_NextID++), m_ThreadCount(threadCount), m_MaxItems(maxItems),
m_TaskStats(15 * 60), m_StatsLogLevel(statsLogLevel)
m_TaskStats(15 * 60)
{
/* Initialize logger. */
m_StatusTimerTimeout = Utility::GetTime();
Expand Down Expand Up @@ -216,7 +216,7 @@ void WorkQueue::StatusTimerHandler()

/* Log if there are pending items, or 5 minute timeout is reached. */
if (pending > 0 || m_StatusTimerTimeout < now) {
Log(m_StatsLogLevel, "WorkQueue")
Log(LogNotice, "WorkQueue")
<< "#" << m_ID << " (" << m_Name << ") "
<< "items: " << pending << ", "
<< "rate: " << std::setw(2) << GetTaskCount(60) / 60.0 << "/s "
Expand Down
4 changes: 1 addition & 3 deletions lib/base/workqueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "base/i2-base.hpp"
#include "base/timer.hpp"
#include "base/ringbuffer.hpp"
#include "base/logger.hpp"
#include <boost/thread/thread.hpp>
#include <boost/exception_ptr.hpp>
#include <condition_variable>
Expand Down Expand Up @@ -53,7 +52,7 @@ class WorkQueue
public:
typedef std::function<void (boost::exception_ptr)> ExceptionCallback;

WorkQueue(size_t maxItems = 0, int threadCount = 1, LogSeverity statsLogLevel = LogInformation);
WorkQueue(size_t maxItems = 0, int threadCount = 1);
~WorkQueue();

void SetName(const String& name);
Expand Down Expand Up @@ -137,7 +136,6 @@ class WorkQueue
std::vector<boost::exception_ptr> m_Exceptions;
Timer::Ptr m_StatusTimer;
double m_StatusTimerTimeout;
LogSeverity m_StatsLogLevel;

RingBuffer m_TaskStats;
size_t m_PendingTasks{0};
Expand Down
2 changes: 1 addition & 1 deletion lib/db_ido/dbconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class DbConnection : public ObjectImpl<DbConnection>
void IncreasePendingQueries(int count);
void DecreasePendingQueries(int count);

WorkQueue m_QueryQueue{10000000, 1, LogNotice};
WorkQueue m_QueryQueue{10000000};

private:
bool m_IDCacheValid{false};
Expand Down
2 changes: 1 addition & 1 deletion lib/icinga/checkable-notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr&
return;
}

Log(LogInformation, "Checkable")
Log(LogNotice, "Checkable")
<< "Checkable '" << checkableName << "' has " << notifications.size()
<< " notification(s). Checking filters for type '" << notificationTypeName << "', sends will be logged.";

Expand Down
2 changes: 2 additions & 0 deletions lib/icinga/checkable.ti
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ abstract class Checkable : CustomVarObject
default {{{ return true; }}}
};

[no_user_view, no_user_modify] bool logged_invalid_perfdata;

[config] array(String) flapping_ignore_states;
[no_user_view, no_user_modify] int flapping_ignore_states_filter_real (FlappingIgnoreStatesFilter);

Expand Down
4 changes: 2 additions & 2 deletions lib/icinga/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
}
}

Log(LogInformation, "Notification")
Log(LogNotice, "Notification")
<< "Sending " << (reminder ? "reminder " : "") << "'" << NotificationTypeToString(type) << "' notification '"
<< notificationName << "' for user '" << userName << "'";

Expand Down Expand Up @@ -562,7 +562,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
/* required by compatlogger */
Service::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, author, text, commandName, nullptr);

Log(LogInformation, "Notification")
Log(LogNotice, "Notification")
<< "Completed sending '" << NotificationTypeToString(type)
<< "' notification '" << notificationName
<< "' for checkable '" << checkableName
Expand Down
4 changes: 2 additions & 2 deletions lib/icingadb/icingadb-objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void IcingaDB::UpdateAllConfigObjects()
});

// Use a Workqueue to pack objects in parallel
WorkQueue upq(25000, Configuration::Concurrency, LogNotice);
WorkQueue upq(25000, Configuration::Concurrency);
upq.SetName("IcingaDB:ConfigDump");

std::vector<Type::Ptr> types = GetTypes();
Expand Down Expand Up @@ -228,7 +228,7 @@ void IcingaDB::UpdateAllConfigObjects()
std::vector<String> keys = GetTypeOverwriteKeys(lcType);
DeleteKeys(rcon, keys, Prio::Config);

WorkQueue upqObjectType(25000, Configuration::Concurrency, LogNotice);
WorkQueue upqObjectType(25000, Configuration::Concurrency);
upqObjectType.SetName("IcingaDB:ConfigDump:" + lcType);

std::map<String, String> redisCheckSums;
Expand Down
2 changes: 1 addition & 1 deletion lib/icingadb/icingadb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class IcingaDB : public ObjectImpl<IcingaDB>
static void PersistEnvironmentId();

Timer::Ptr m_StatsTimer;
WorkQueue m_WorkQueue{0, 1, LogNotice};
WorkQueue m_WorkQueue;

std::future<void> m_HistoryThread;
Bulker<RedisConnection::Query> m_HistoryBulker {4096, std::chrono::milliseconds(250)};
Expand Down
10 changes: 9 additions & 1 deletion lib/perfdata/elasticsearchwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void ElasticsearchWriter::AddCheckResult(const Dictionary::Ptr& fields, const Ch
CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();

if (perfdata) {
bool hasInvalidPerfdata = false;
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;
Expand All @@ -166,10 +167,13 @@ void ElasticsearchWriter::AddCheckResult(const Dictionary::Ptr& fields, const Ch
try {
pdv = PerfdataValue::Parse(val);
} catch (const std::exception&) {
Log(LogWarning, "ElasticsearchWriter")
Log(checkable->GetLoggedInvalidPerfdata() ? LogNotice : LogWarning, "ElasticsearchWriter")
<< "Ignoring invalid perfdata for checkable '"
<< checkable->GetName() << "' and command '"
<< checkCommand->GetName() << "' with value: " << val;

checkable->SetLoggedInvalidPerfdata(true);
hasInvalidPerfdata = true;
continue;
}
}
Expand All @@ -196,6 +200,10 @@ void ElasticsearchWriter::AddCheckResult(const Dictionary::Ptr& fields, const Ch
if (!pdv->GetUnit().IsEmpty())
fields->Set(perfdataPrefix + ".unit", pdv->GetUnit());
}

if (!hasInvalidPerfdata && perfdata->GetLength()) {
checkable->SetLoggedInvalidPerfdata(false);
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion lib/perfdata/gelfwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con
Array::Ptr perfdata = cr->GetPerformanceData();

if (perfdata) {
bool hasInvalidPerfdata = false;
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;
Expand All @@ -336,10 +337,13 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con
try {
pdv = PerfdataValue::Parse(val);
} catch (const std::exception&) {
Log(LogWarning, "GelfWriter")
Log(checkable->GetLoggedInvalidPerfdata() ? LogNotice : LogWarning, "GelfWriter")
<< "Ignoring invalid perfdata for checkable '"
<< checkable->GetName() << "' and command '"
<< checkCommand->GetName() << "' with value: " << val;

checkable->SetLoggedInvalidPerfdata(true);
hasInvalidPerfdata = true;
continue;
}
}
Expand All @@ -364,6 +368,10 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con
if (!pdv->GetUnit().IsEmpty())
fields->Set("_" + escaped_key + "_unit", pdv->GetUnit());
}

if (!hasInvalidPerfdata && perfdata->GetLength()) {
checkable->SetLoggedInvalidPerfdata(false);
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion lib/perfdata/graphitewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ void GraphiteWriter::SendPerfdata(const Checkable::Ptr& checkable, const String&

CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();

bool hasInvalidPerfdata = false;
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;
Expand All @@ -359,10 +360,13 @@ void GraphiteWriter::SendPerfdata(const Checkable::Ptr& checkable, const String&
try {
pdv = PerfdataValue::Parse(val);
} catch (const std::exception&) {
Log(LogWarning, "GraphiteWriter")
Log(checkable->GetLoggedInvalidPerfdata() ? LogNotice : LogWarning, "GraphiteWriter")
<< "Ignoring invalid perfdata for checkable '"
<< checkable->GetName() << "' and command '"
<< checkCommand->GetName() << "' with value: " << val;

checkable->SetLoggedInvalidPerfdata(true);
hasInvalidPerfdata = true;
continue;
}
}
Expand All @@ -382,6 +386,10 @@ void GraphiteWriter::SendPerfdata(const Checkable::Ptr& checkable, const String&
SendMetric(checkable, prefix, escapedKey + ".max", pdv->GetMax(), ts);
}
}

if (!hasInvalidPerfdata && perfdata->GetLength()) {
checkable->SetLoggedInvalidPerfdata(false);
}
}

/**
Expand Down
11 changes: 10 additions & 1 deletion lib/perfdata/influxdbcommonwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ void InfluxdbCommonWriter::CheckResultHandlerWQ(const Checkable::Ptr& checkable,
Array::Ptr perfdata = cr->GetPerformanceData();

if (perfdata) {
bool hasInvalidPerfdata = false;
ObjectLock olock(perfdata);

for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;

Expand All @@ -268,10 +270,13 @@ void InfluxdbCommonWriter::CheckResultHandlerWQ(const Checkable::Ptr& checkable,
try {
pdv = PerfdataValue::Parse(val);
} catch (const std::exception&) {
Log(LogWarning, GetReflectionType()->GetName())
Log(checkable->GetLoggedInvalidPerfdata() ? LogNotice : LogWarning, GetReflectionType()->GetName())
<< "Ignoring invalid perfdata for checkable '"
<< checkable->GetName() << "' and command '"
<< checkCommand->GetName() << "' with value: " << val;

checkable->SetLoggedInvalidPerfdata(true);
hasInvalidPerfdata = true;
continue;
}
}
Expand All @@ -295,6 +300,10 @@ void InfluxdbCommonWriter::CheckResultHandlerWQ(const Checkable::Ptr& checkable,

SendMetric(checkable, tmpl, pdv->GetLabel(), fields, ts);
}

if (!hasInvalidPerfdata && perfdata->GetLength()) {
checkable->SetLoggedInvalidPerfdata(false);
}
}

if (GetEnableSendMetadata()) {
Expand Down
10 changes: 9 additions & 1 deletion lib/perfdata/opentsdbwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ void OpenTsdbWriter::SendPerfdata(const Checkable::Ptr& checkable, const String&

CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();

bool hasInvalidPerfdata = false;
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;
Expand All @@ -319,10 +320,13 @@ void OpenTsdbWriter::SendPerfdata(const Checkable::Ptr& checkable, const String&
try {
pdv = PerfdataValue::Parse(val);
} catch (const std::exception&) {
Log(LogWarning, "OpenTsdbWriter")
Log(checkable->GetLoggedInvalidPerfdata() ? LogNotice : LogWarning, "OpenTsdbWriter")
<< "Ignoring invalid perfdata for checkable '"
<< checkable->GetName() << "' and command '"
<< checkCommand->GetName() << "' with value: " << val;

checkable->SetLoggedInvalidPerfdata(true);
hasInvalidPerfdata = true;
continue;
}
}
Expand Down Expand Up @@ -353,6 +357,10 @@ void OpenTsdbWriter::SendPerfdata(const Checkable::Ptr& checkable, const String&
if (!pdv->GetMax().IsEmpty())
SendMetric(checkable, metric_name + "_max", tags_new, pdv->GetMax(), ts);
}

if (!hasInvalidPerfdata && perfdata->GetLength()) {
checkable->SetLoggedInvalidPerfdata(false);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/remote/apilistener-configsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient

Zone::Ptr azone = endpoint->GetZone();

Log(LogInformation, "ApiListener")
Log(LogNotice, "ApiListener")
<< "Syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";

for (const Type::Ptr& type : Type::GetAllTypes()) {
Expand All @@ -469,6 +469,6 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient
}
}

Log(LogInformation, "ApiListener")
Log(LogNotice, "ApiListener")
<< "Finished syncing runtime objects to endpoint '" << endpoint->GetName() << "'.";
}
2 changes: 1 addition & 1 deletion lib/remote/apilistener-filesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void ApiListener::SendConfigUpdate(const JsonRpcConnection::Ptr& aclient)
if (!Utility::PathExists(zoneDir))
continue;

Log(LogInformation, "ApiListener")
Log(LogNotice, "ApiListener")
<< "Syncing configuration files for " << (zone->IsGlobal() ? "global " : "")
<< "zone '" << zoneName << "' to endpoint '" << endpoint->GetName() << "'.";

Expand Down
Loading