mirror of https://github.com/Icinga/icinga2.git
Merge pull request #7421 from Icinga/feature/threadpool-metric
Expose metric current_pending_callbacks
This commit is contained in:
commit
c2e1d023e2
|
@ -6,7 +6,7 @@
|
|||
using namespace icinga;
|
||||
|
||||
ThreadPool::ThreadPool(size_t threads)
|
||||
: m_Threads(threads)
|
||||
: m_Threads(threads), m_Pending(0)
|
||||
{
|
||||
Start();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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()));
|
||||
|
||||
|
|
Loading…
Reference in New Issue