mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-07-07 05:21:42 -07:00
Add prom metrics for Central controller specific things
This commit is contained in:
parent
328180d2e5
commit
09d7132be0
3 changed files with 30 additions and 1 deletions
|
@ -19,6 +19,8 @@
|
|||
#define _DEBUG(x)
|
||||
#endif
|
||||
|
||||
#include <prometheus/simpleapi.h>
|
||||
|
||||
#include <deque>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
|
@ -61,6 +63,7 @@ public:
|
|||
{
|
||||
while(m_pool.size() < m_minPoolSize){
|
||||
m_pool.push_back(m_factory->create());
|
||||
_pool_avail++;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -91,6 +94,7 @@ public:
|
|||
while((m_pool.size() + m_borrowed.size()) < m_minPoolSize) {
|
||||
std::shared_ptr<Connection> conn = m_factory->create();
|
||||
m_pool.push_back(conn);
|
||||
_pool_avail++;
|
||||
}
|
||||
|
||||
if(m_pool.size()==0){
|
||||
|
@ -99,6 +103,7 @@ public:
|
|||
try {
|
||||
std::shared_ptr<Connection> conn = m_factory->create();
|
||||
m_borrowed.insert(conn);
|
||||
_pool_in_use++;
|
||||
return std::static_pointer_cast<T>(conn);
|
||||
} catch (std::exception &e) {
|
||||
throw ConnectionUnavailable();
|
||||
|
@ -128,8 +133,10 @@ public:
|
|||
// Take one off the front
|
||||
std::shared_ptr<Connection> conn = m_pool.front();
|
||||
m_pool.pop_front();
|
||||
_pool_avail--;
|
||||
// Add it to the borrowed list
|
||||
m_borrowed.insert(conn);
|
||||
_pool_in_use++;
|
||||
return std::static_pointer_cast<T>(conn);
|
||||
};
|
||||
|
||||
|
@ -143,7 +150,9 @@ public:
|
|||
// Lock
|
||||
std::unique_lock<std::mutex> lock(m_poolMutex);
|
||||
m_borrowed.erase(conn);
|
||||
_pool_in_use--;
|
||||
if ((m_pool.size() + m_borrowed.size()) < m_maxPoolSize) {
|
||||
_pool_avail++;
|
||||
m_pool.push_back(conn);
|
||||
}
|
||||
};
|
||||
|
@ -154,8 +163,14 @@ protected:
|
|||
std::deque<std::shared_ptr<Connection> > m_pool;
|
||||
std::set<std::shared_ptr<Connection> > m_borrowed;
|
||||
std::mutex m_poolMutex;
|
||||
|
||||
prometheus::simpleapi::counter_metric_t _max_pool_size { "controller_pgsql_max_conn_pool_size", "max connection pool size for postgres"};
|
||||
prometheus::simpleapi::counter_metric_t _min_pool_size { "controller_pgsql_min_conn_pool_size", "minimum connection pool size for postgres" };
|
||||
prometheus::simpleapi::gauge_metric_t _pool_avail { "controller_pgsql_available_conns", "number of available postgres connections" };
|
||||
prometheus::simpleapi::gauge_metric_t _pool_in_use { "controller_pgsql_in_use_conns", "number of postgres database connections in use" };
|
||||
prometheus::simpleapi::counter_metric_t _pool_errors { "controller_pgsql_connection_errors", "number of connection errors the connection pool has seen" };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue