mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02: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)
|
#define _DEBUG(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <prometheus/simpleapi.h>
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -61,6 +63,7 @@ public:
|
||||||
{
|
{
|
||||||
while(m_pool.size() < m_minPoolSize){
|
while(m_pool.size() < m_minPoolSize){
|
||||||
m_pool.push_back(m_factory->create());
|
m_pool.push_back(m_factory->create());
|
||||||
|
_pool_avail++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ public:
|
||||||
while((m_pool.size() + m_borrowed.size()) < m_minPoolSize) {
|
while((m_pool.size() + m_borrowed.size()) < m_minPoolSize) {
|
||||||
std::shared_ptr<Connection> conn = m_factory->create();
|
std::shared_ptr<Connection> conn = m_factory->create();
|
||||||
m_pool.push_back(conn);
|
m_pool.push_back(conn);
|
||||||
|
_pool_avail++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_pool.size()==0){
|
if(m_pool.size()==0){
|
||||||
|
@ -99,6 +103,7 @@ public:
|
||||||
try {
|
try {
|
||||||
std::shared_ptr<Connection> conn = m_factory->create();
|
std::shared_ptr<Connection> conn = m_factory->create();
|
||||||
m_borrowed.insert(conn);
|
m_borrowed.insert(conn);
|
||||||
|
_pool_in_use++;
|
||||||
return std::static_pointer_cast<T>(conn);
|
return std::static_pointer_cast<T>(conn);
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
throw ConnectionUnavailable();
|
throw ConnectionUnavailable();
|
||||||
|
@ -128,8 +133,10 @@ public:
|
||||||
// Take one off the front
|
// Take one off the front
|
||||||
std::shared_ptr<Connection> conn = m_pool.front();
|
std::shared_ptr<Connection> conn = m_pool.front();
|
||||||
m_pool.pop_front();
|
m_pool.pop_front();
|
||||||
|
_pool_avail--;
|
||||||
// Add it to the borrowed list
|
// Add it to the borrowed list
|
||||||
m_borrowed.insert(conn);
|
m_borrowed.insert(conn);
|
||||||
|
_pool_in_use++;
|
||||||
return std::static_pointer_cast<T>(conn);
|
return std::static_pointer_cast<T>(conn);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -143,7 +150,9 @@ public:
|
||||||
// Lock
|
// Lock
|
||||||
std::unique_lock<std::mutex> lock(m_poolMutex);
|
std::unique_lock<std::mutex> lock(m_poolMutex);
|
||||||
m_borrowed.erase(conn);
|
m_borrowed.erase(conn);
|
||||||
|
_pool_in_use--;
|
||||||
if ((m_pool.size() + m_borrowed.size()) < m_maxPoolSize) {
|
if ((m_pool.size() + m_borrowed.size()) < m_maxPoolSize) {
|
||||||
|
_pool_avail++;
|
||||||
m_pool.push_back(conn);
|
m_pool.push_back(conn);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -154,8 +163,14 @@ protected:
|
||||||
std::deque<std::shared_ptr<Connection> > m_pool;
|
std::deque<std::shared_ptr<Connection> > m_pool;
|
||||||
std::set<std::shared_ptr<Connection> > m_borrowed;
|
std::set<std::shared_ptr<Connection> > m_borrowed;
|
||||||
std::mutex m_poolMutex;
|
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
|
||||||
|
|
|
@ -119,6 +119,7 @@ MemberNotificationReceiver::MemberNotificationReceiver(PostgreSQL *p, pqxx::conn
|
||||||
|
|
||||||
void MemberNotificationReceiver::operator() (const std::string &payload, int packend_pid) {
|
void MemberNotificationReceiver::operator() (const std::string &payload, int packend_pid) {
|
||||||
fprintf(stderr, "Member Notification received: %s\n", payload.c_str());
|
fprintf(stderr, "Member Notification received: %s\n", payload.c_str());
|
||||||
|
_mem_notifications++;
|
||||||
json tmp(json::parse(payload));
|
json tmp(json::parse(payload));
|
||||||
json &ov = tmp["old_val"];
|
json &ov = tmp["old_val"];
|
||||||
json &nv = tmp["new_val"];
|
json &nv = tmp["new_val"];
|
||||||
|
@ -141,6 +142,7 @@ NetworkNotificationReceiver::NetworkNotificationReceiver(PostgreSQL *p, pqxx::co
|
||||||
|
|
||||||
void NetworkNotificationReceiver::operator() (const std::string &payload, int packend_pid) {
|
void NetworkNotificationReceiver::operator() (const std::string &payload, int packend_pid) {
|
||||||
fprintf(stderr, "Network Notification received: %s\n", payload.c_str());
|
fprintf(stderr, "Network Notification received: %s\n", payload.c_str());
|
||||||
|
_net_notifications++;
|
||||||
json tmp(json::parse(payload));
|
json tmp(json::parse(payload));
|
||||||
json &ov = tmp["old_val"];
|
json &ov = tmp["old_val"];
|
||||||
json &nv = tmp["new_val"];
|
json &nv = tmp["new_val"];
|
||||||
|
@ -1233,6 +1235,7 @@ void PostgreSQL::_networksWatcher_Redis() {
|
||||||
}
|
}
|
||||||
lastID = id;
|
lastID = id;
|
||||||
}
|
}
|
||||||
|
_redis_net_notif++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (sw::redis::Error &e) {
|
} catch (sw::redis::Error &e) {
|
||||||
|
@ -1791,6 +1794,7 @@ uint64_t PostgreSQL::_doRedisUpdate(sw::redis::Transaction &tx, std::string &con
|
||||||
.sadd("network-nodes-all:{"+controllerId+"}:"+networkId, memberId)
|
.sadd("network-nodes-all:{"+controllerId+"}:"+networkId, memberId)
|
||||||
.hmset("member:{"+controllerId+"}:"+networkId+":"+memberId, record.begin(), record.end());
|
.hmset("member:{"+controllerId+"}:"+networkId+":"+memberId, record.begin(), record.end());
|
||||||
++count;
|
++count;
|
||||||
|
_redis_mem_notif++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// expire records from all-nodes and network-nodes member list
|
// expire records from all-nodes and network-nodes member list
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <redis++/redis++.h>
|
#include <redis++/redis++.h>
|
||||||
|
|
||||||
|
#include <prometheus/simpleapi.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
typedef struct pg_conn PGconn;
|
typedef struct pg_conn PGconn;
|
||||||
}
|
}
|
||||||
|
@ -53,12 +55,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::shared_ptr<Connection> create() {
|
virtual std::shared_ptr<Connection> create() {
|
||||||
|
_conn_counter++;
|
||||||
auto c = std::shared_ptr<PostgresConnection>(new PostgresConnection());
|
auto c = std::shared_ptr<PostgresConnection>(new PostgresConnection());
|
||||||
c->c = std::make_shared<pqxx::connection>(m_connString);
|
c->c = std::make_shared<pqxx::connection>(m_connString);
|
||||||
return std::static_pointer_cast<Connection>(c);
|
return std::static_pointer_cast<Connection>(c);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::string m_connString;
|
std::string m_connString;
|
||||||
|
prometheus::simpleapi::counter_metric_t _conn_counter { "controller_pgsql_connections_created", "number of pgsql connections created" };
|
||||||
};
|
};
|
||||||
|
|
||||||
class PostgreSQL;
|
class PostgreSQL;
|
||||||
|
@ -73,6 +77,7 @@ public:
|
||||||
virtual void operator() (const std::string &payload, int backendPid);
|
virtual void operator() (const std::string &payload, int backendPid);
|
||||||
private:
|
private:
|
||||||
PostgreSQL *_psql;
|
PostgreSQL *_psql;
|
||||||
|
prometheus::simpleapi::counter_metric_t _mem_notifications { "controller_pgsql_member_notifications_received", "number of member change notifications received via pgsql NOTIFY" };
|
||||||
};
|
};
|
||||||
|
|
||||||
class NetworkNotificationReceiver : public pqxx::notification_receiver {
|
class NetworkNotificationReceiver : public pqxx::notification_receiver {
|
||||||
|
@ -85,6 +90,7 @@ public:
|
||||||
virtual void operator() (const std::string &payload, int packend_pid);
|
virtual void operator() (const std::string &payload, int packend_pid);
|
||||||
private:
|
private:
|
||||||
PostgreSQL *_psql;
|
PostgreSQL *_psql;
|
||||||
|
prometheus::simpleapi::counter_metric_t _net_notifications { "controller_pgsql_network_notifications_received", "number of network change notifications received via pgsql NOTIFY" };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,6 +181,10 @@ private:
|
||||||
std::shared_ptr<sw::redis::Redis> _redis;
|
std::shared_ptr<sw::redis::Redis> _redis;
|
||||||
std::shared_ptr<sw::redis::RedisCluster> _cluster;
|
std::shared_ptr<sw::redis::RedisCluster> _cluster;
|
||||||
bool _redisMemberStatus;
|
bool _redisMemberStatus;
|
||||||
|
|
||||||
|
prometheus::simpleapi::counter_metric_t _redis_mem_notif { "controller_redis_member_notifications_received", "number of member change notifications received via redis" };
|
||||||
|
prometheus::simpleapi::counter_metric_t _redis_net_notif { "controller_redis_network_notifications_received", "number of network change notifications received via redis" };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
|
Loading…
Add table
Reference in a new issue