From cd20044e4f3b93393a950568f09740d7b5c20ae9 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 13 Mar 2015 12:00:30 +0100 Subject: [PATCH] Implement the pending_queries metric for the IDO check task refs #8688 --- lib/base/workqueue.cpp | 2 +- lib/base/workqueue.hpp | 2 +- lib/db_ido/dbconnection.hpp | 1 + lib/db_ido/idochecktask.cpp | 1 + lib/db_ido_mysql/idomysqlconnection.cpp | 5 +++++ lib/db_ido_mysql/idomysqlconnection.hpp | 2 ++ lib/db_ido_pgsql/idopgsqlconnection.cpp | 5 +++++ lib/db_ido_pgsql/idopgsqlconnection.hpp | 4 +++- 8 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/base/workqueue.cpp b/lib/base/workqueue.cpp index c3259309a..615d21d3a 100644 --- a/lib/base/workqueue.cpp +++ b/lib/base/workqueue.cpp @@ -166,7 +166,7 @@ void WorkQueue::ReportExceptions(const String& facility) const << exceptions.size() << " error" << (exceptions.size() != 1 ? "s" : ""); } -size_t WorkQueue::GetLength(void) +size_t WorkQueue::GetLength(void) const { boost::mutex::scoped_lock lock(m_Mutex); diff --git a/lib/base/workqueue.hpp b/lib/base/workqueue.hpp index 871955d55..5d5de7465 100644 --- a/lib/base/workqueue.hpp +++ b/lib/base/workqueue.hpp @@ -52,7 +52,7 @@ public: bool IsWorkerThread(void) const; - size_t GetLength(void); + size_t GetLength(void) const; void SetExceptionCallback(const ExceptionCallback& callback); diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp index 529c45069..243744258 100644 --- a/lib/db_ido/dbconnection.hpp +++ b/lib/db_ido/dbconnection.hpp @@ -72,6 +72,7 @@ public: bool GetStatusUpdate(const DbObject::Ptr& dbobj) const; int GetQueryCount(RingBuffer::SizeType span) const; + virtual int GetPendingQueryCount(void) const = 0; static void ValidateFailoverTimeout(const String& location, const DbConnection::Ptr& object); diff --git a/lib/db_ido/idochecktask.cpp b/lib/db_ido/idochecktask.cpp index 6c85086cd..ed9b4ffed 100644 --- a/lib/db_ido/idochecktask.cpp +++ b/lib/db_ido/idochecktask.cpp @@ -121,6 +121,7 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult perfdata->Add(new PerfdataValue("queries_1min", conn->GetQueryCount(60))); perfdata->Add(new PerfdataValue("queries_5mins", conn->GetQueryCount(5 * 60))); perfdata->Add(new PerfdataValue("queries_15mins", conn->GetQueryCount(15 * 60))); + perfdata->Add(new PerfdataValue("pending_queries", conn->GetPendingQueryCount())); cr->SetPerformanceData(perfdata); checkable->ProcessCheckResult(cr); diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index bf2f660cc..b05a3bde2 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -770,3 +770,8 @@ void IdoMysqlConnection::FillIDCache(const DbType::Ptr& type) SetInsertID(type, DbReference(row->Get("object_id")), DbReference(row->Get(type->GetTable() + "_id"))); } } + +int IdoMysqlConnection::GetPendingQueryCount(void) const +{ + return m_QueryQueue.GetLength(); +} diff --git a/lib/db_ido_mysql/idomysqlconnection.hpp b/lib/db_ido_mysql/idomysqlconnection.hpp index 5985f5813..623fe465b 100644 --- a/lib/db_ido_mysql/idomysqlconnection.hpp +++ b/lib/db_ido_mysql/idomysqlconnection.hpp @@ -46,6 +46,8 @@ public: static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); + virtual int GetPendingQueryCount(void) const; + protected: virtual void Resume(void); virtual void Pause(void); diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index 122075a4f..dd8884736 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -781,3 +781,8 @@ void IdoPgsqlConnection::FillIDCache(const DbType::Ptr& type) SetInsertID(type, DbReference(row->Get("object_id")), DbReference(row->Get(type->GetTable() + "_id"))); } } + +int IdoPgsqlConnection::GetPendingQueryCount(void) const +{ + return m_QueryQueue.GetLength(); +} diff --git a/lib/db_ido_pgsql/idopgsqlconnection.hpp b/lib/db_ido_pgsql/idopgsqlconnection.hpp index 4f7bf9d7d..8ec15a93e 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.hpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.hpp @@ -42,10 +42,12 @@ public: DECLARE_OBJECT(IdoPgsqlConnection); DECLARE_OBJECTNAME(IdoPgsqlConnection); - IdoPgsqlConnection(void); + IdoPgsqlConnection(void); static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); + virtual int GetPendingQueryCount(void) const; + protected: virtual void Resume(void); virtual void Pause(void);