Merge pull request #7421 from Icinga/feature/threadpool-metric

Expose metric current_pending_callbacks
This commit is contained in:
Michael Friedrich 2019-08-15 10:51:31 +02:00 committed by GitHub
commit c2e1d023e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 2 deletions

View File

@ -6,7 +6,7 @@
using namespace icinga;
ThreadPool::ThreadPool(size_t threads)
: m_Threads(threads)
: m_Threads(threads), m_Pending(0)
{
Start();
}

View File

@ -3,6 +3,7 @@
#ifndef THREADPOOL_H
#define THREADPOOL_H
#include "base/atomic.hpp"
#include "base/exception.hpp"
#include "base/logger.hpp"
#include <cstddef>
@ -14,6 +15,7 @@
#include <boost/asio/thread_pool.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <cstdint>
namespace icinga
{
@ -52,7 +54,11 @@ public:
boost::shared_lock<decltype(m_Mutex)> lock (m_Mutex);
if (m_Pool) {
boost::asio::post(*m_Pool, [callback]() {
m_Pending.fetch_add(1);
boost::asio::post(*m_Pool, [this, callback]() {
m_Pending.fetch_sub(1);
try {
callback();
} catch (const std::exception& ex) {
@ -70,10 +76,21 @@ public:
}
}
/**
* Returns the amount of queued tasks not started yet.
*
* @returns amount of queued tasks.
*/
inline uint_fast64_t GetPending()
{
return m_Pending.load();
}
private:
boost::shared_mutex m_Mutex;
std::unique_ptr<boost::asio::thread_pool> m_Pool;
size_t m_Threads;
Atomic<uint_fast64_t> m_Pending;
};
}

View File

@ -4,6 +4,7 @@
#include "icinga/host.hpp"
#include "icinga/service.hpp"
#include "icinga/clusterevents.hpp"
#include "base/application.hpp"
#include "base/objectlock.hpp"
#include "base/utility.hpp"
#include "base/perfdatavalue.hpp"
@ -292,6 +293,7 @@ void CIB::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata) {
// Checker related stats
status->Set("remote_check_queue", ClusterEvents::GetCheckRequestQueueSize());
status->Set("current_concurrent_checks", Checkable::GetPendingChecks());
status->Set("current_pending_callbacks", Application::GetTP().GetPending());
CheckableCheckStatistics scs = CalculateServiceCheckStats();

View File

@ -75,6 +75,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
perfdata->Add(new PerfdataValue("active_service_checks_15min", CIB::GetActiveServiceChecksStatistics(60 * 15)));
perfdata->Add(new PerfdataValue("passive_service_checks_15min", CIB::GetPassiveServiceChecksStatistics(60 * 15)));
perfdata->Add(new PerfdataValue("current_pending_callbacks", Application::GetTP().GetPending()));
perfdata->Add(new PerfdataValue("current_concurrent_checks", Checkable::GetPendingChecks()));
perfdata->Add(new PerfdataValue("remote_check_queue", ClusterEvents::GetCheckRequestQueueSize()));