reorganize metric initialization

This commit is contained in:
Grant Limberg 2023-04-19 16:19:05 -07:00
parent 879d66162c
commit bd8f048bef
No known key found for this signature in database
GPG key ID: 8F2F97D3BE8D7735
4 changed files with 24 additions and 13 deletions

View file

@ -101,7 +101,14 @@ void DB::cleanMember(nlohmann::json &member)
member.erase("authenticationClientID"); // computed
}
DB::DB() {}
DB::DB()
: _network_count{"controller_network_count", "number of networks the controller is serving"}
, _member_count{"controller_member_count", "number of network members the controller is serving"}
, _network_changes{"controller_network_change_count", "number of times a network configuration is changed"}
, _member_changes{"controller_member_change_count", "number of times a network member configuration is changed"}
, _member_auths{"controller_member_auth_count", "number of network member auths"}
, _member_deauths{"controller_member_deauth_count", "number of network member deauths"}
{}
DB::~DB() {}
bool DB::get(const uint64_t networkId,nlohmann::json &network)

View file

@ -191,12 +191,12 @@ protected:
mutable std::mutex _changeListeners_l;
mutable std::mutex _networks_l;
prometheus::simpleapi::gauge_metric_t _network_count { "controller_network_count", "number of networks the controller is serving" };
prometheus::simpleapi::gauge_metric_t _member_count { "controller_member_count", "number of network members the controller is serving" };
prometheus::simpleapi::counter_metric_t _network_changes { "controller_network_change_count", "number of times a network configuration is changed" };
prometheus::simpleapi::counter_metric_t _member_changes { "controller_member_change_count", "number of times a network member configuration is changed" };
prometheus::simpleapi::counter_metric_t _member_auths { "controller_member_auth_count", "number of network member auths" };
prometheus::simpleapi::counter_metric_t _member_deauths { "controller_member_deauth_count", "number of network member deauths" };
prometheus::simpleapi::gauge_metric_t _network_count;
prometheus::simpleapi::gauge_metric_t _member_count;
prometheus::simpleapi::counter_metric_t _network_changes;
prometheus::simpleapi::counter_metric_t _member_changes;
prometheus::simpleapi::counter_metric_t _member_auths;
prometheus::simpleapi::counter_metric_t _member_deauths;
};
} // namespace ZeroTier

View file

@ -112,6 +112,7 @@ using namespace ZeroTier;
MemberNotificationReceiver::MemberNotificationReceiver(PostgreSQL *p, pqxx::connection &c, const std::string &channel)
: pqxx::notification_receiver(c, channel)
, _psql(p)
, _mem_notifications{"controller_pgsql_member_notifications_received", "number of member change notifications received via pgsql NOTIFY"}
{
fprintf(stderr, "initialize MemberNotificationReceiver\n");
}
@ -136,6 +137,7 @@ void MemberNotificationReceiver::operator() (const std::string &payload, int pac
NetworkNotificationReceiver::NetworkNotificationReceiver(PostgreSQL *p, pqxx::connection &c, const std::string &channel)
: pqxx::notification_receiver(c, channel)
, _psql(p)
, _net_notifications{"controller_pgsql_network_notifications_received", "number of network change notifications received via pgsql NOTIFY"}
{
fprintf(stderr, "initialize NetworkNotificationReceiver\n");
}
@ -173,6 +175,8 @@ PostgreSQL::PostgreSQL(const Identity &myId, const char *path, int listenPort, R
, _redis(NULL)
, _cluster(NULL)
, _redisMemberStatus(false)
, _redis_mem_notif{"controller_redis_member_notifications_received", "number of member change notifications received via redis"}
, _redis_net_notif{"controller_redis_network_notifications_received", "number of network change notifications received via redis"}
{
char myAddress[64];
_myAddressStr = myId.address().toString(myAddress);

View file

@ -51,6 +51,7 @@ class PostgresConnFactory : public ConnectionFactory {
public:
PostgresConnFactory(std::string &connString)
: m_connString(connString)
, _conn_counter{ "controller_pgsql_connections_created", "number of pgsql connections created"}
{
}
@ -62,7 +63,7 @@ public:
}
private:
std::string m_connString;
prometheus::simpleapi::counter_metric_t _conn_counter { "controller_pgsql_connections_created", "number of pgsql connections created" };
prometheus::simpleapi::counter_metric_t _conn_counter;
};
class PostgreSQL;
@ -77,7 +78,7 @@ public:
virtual void operator() (const std::string &payload, int backendPid);
private:
PostgreSQL *_psql;
prometheus::simpleapi::counter_metric_t _mem_notifications { "controller_pgsql_member_notifications_received", "number of member change notifications received via pgsql NOTIFY" };
prometheus::simpleapi::counter_metric_t _mem_notifications;
};
class NetworkNotificationReceiver : public pqxx::notification_receiver {
@ -90,7 +91,7 @@ public:
virtual void operator() (const std::string &payload, int packend_pid);
private:
PostgreSQL *_psql;
prometheus::simpleapi::counter_metric_t _net_notifications { "controller_pgsql_network_notifications_received", "number of network change notifications received via pgsql NOTIFY" };
prometheus::simpleapi::counter_metric_t _net_notifications;
};
/**
@ -182,9 +183,8 @@ private:
std::shared_ptr<sw::redis::RedisCluster> _cluster;
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" };
prometheus::simpleapi::counter_metric_t _redis_mem_notif;
prometheus::simpleapi::counter_metric_t _redis_net_notif;
};
} // namespace ZeroTier