Skip to content

Commit

Permalink
Support for modb counts in opflex-agent
Browse files Browse the repository at this point in the history
- Added support for modb counts per object type for few objects. More object counts can be added in future.
- Updated MoDBCount MO with what we display now.
- Removed redundant active_ep_count and active_svc_count.
- did some misc cleanup.
- added tests for modb counts

TODO:
Move OFPeer and MoBDCount updates to a new class (currently under PolicyStatsManager)
Remove created/removed counts of EP and SVC - customers can just use total ep and svc counts instead
Update Readme for new metrics
Update grafana db templates
Remove HAVE_PROMETHEUS_SUPPORT #define and configuration from agent

Signed-off-by: Gautam Venkataramanan <gautam.chennai@gmail.com>
  • Loading branch information
gautvenk committed Jan 7, 2021
1 parent bec3980 commit 5469c25
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 337 deletions.
312 changes: 139 additions & 173 deletions agent-ovs/lib/AgentPrometheusManager.cpp

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions agent-ovs/lib/EndpointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,6 @@ void EndpointManager::updateEndpointRemote(const opflex::modb::URI& uri) {
}
}
}

#ifdef HAVE_PROMETHEUS_SUPPORT
prometheusManager.addNUpdateRemoteEpCount(remote_ep_uuid_map.size());
#endif
guard.unlock();
if (uuid)
notifyRemoteListeners(uuid.get());
Expand Down
30 changes: 30 additions & 0 deletions agent-ovs/lib/include/opflexagent/EndpointManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,36 @@ class EndpointManager : public PolicyListener,
*/
uint32_t getExtEncapId(const opflex::modb::URI& epgURI);

/**
* Get the total number of local endpoints
*
* @return total local EPs
*/
size_t getEpCount() {
std::lock_guard<std::mutex> guard(ep_mutex);
return ep_map.size();
}

/**
* Get the total number of External endpoints
*
* @return total external EPs
*/
size_t getEpExternalCount() {
std::lock_guard<std::mutex> guard(ep_mutex);
return ext_ep_map.size();
}

/**
* Get the total number of remote endpoints
*
* @return total remote EPs
*/
size_t getEpRemoteCount() {
std::lock_guard<std::mutex> guard(ep_mutex);
return remote_ep_uuid_map.size();
}

private:
/**
* Add or update the endpoint state with new information about an
Expand Down
51 changes: 51 additions & 0 deletions agent-ovs/lib/include/opflexagent/PolicyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,57 @@ class PolicyManager : private boost::noncopyable {
* Handle Subnets deletion
*/
void deleteSubnets(const opflex::modb::URI& subnets);

/**
* Get the total number of contracts
*
* @return total contracts
*/
size_t getContractCount() {
std::lock_guard<std::mutex> guard(state_mutex);
return contractMap.size();
}

/**
* Get the total number of security groups
*
* @return total security groups
*/
size_t getSecGrpCount() {
std::lock_guard<std::mutex> guard(state_mutex);
return secGrpMap.size();
}

/**
* Get the total number of EPGs
*
* @return total EPGs
*/
size_t getEPGCount() {
std::lock_guard<std::mutex> guard(state_mutex);
return group_map.size();
}

/**
* Get the total number of External Interfaces
*
* @return total External Interfaces
*/
size_t getExtIntfCount() {
std::lock_guard<std::mutex> guard(state_mutex);
return ext_int_map.size();
}

/**
* Get the total number of Routing Domains
*
* @return total Routing Domains
*/
size_t getRDCount() {
std::lock_guard<std::mutex> guard(state_mutex);
return rd_map.size();
}

private:
opflex::ofcore::OFFramework& framework;
std::string opflexDomain;
Expand Down
107 changes: 47 additions & 60 deletions agent-ovs/lib/include/opflexagent/PrometheusManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <prometheus/exposer.h>
#include <prometheus/registry.h>

#include <modelgbp/observer/ModbCounts.hpp>

class OFServerStats;
namespace opflexagent {

Expand All @@ -46,6 +48,7 @@ using std::regex;
using std::regex_match;
using std::regex_replace;
using std::lock_guard;
using namespace modelgbp::observer;

class Agent;
struct EpCounters;
Expand Down Expand Up @@ -122,8 +125,6 @@ class PrometheusManager {

// Init state
virtual void init(void) = 0;
// Create any gauge metrics during start
virtual void createStaticGauges(void) {};
// remove any gauge metrics during stop
virtual void removeStaticGauges(void) {};
// create any gauge metric families during start
Expand Down Expand Up @@ -504,15 +505,19 @@ class AgentPrometheusManager : private PrometheusManager {
void decSvcCounter(void);


/* RemoteEp related APIs */
/* MoDB count related APIs */
/**
* Create RemoteEp metric family if its not present.
* Update RemoteEp metric family if its already present
* Create MoDBCounts metric family if its not present.
* Update MoDBCounts metric family if its already present
*
* @param count total number of remote EPs under same uplink
* @param counts contains total number of object counts
* in MoDB per object type
*/
void addNUpdateRemoteEpCount(size_t count);

void addNUpdateMoDBCounts(shared_ptr<ModbCounts> pCounts);
/**
* Remove MoDBCounts metric family
*/
void removeMoDBCounts(void);

/* RDDropCounter related APIs */
/**
Expand Down Expand Up @@ -625,8 +630,6 @@ class AgentPrometheusManager : private PrometheusManager {
opflex::ofcore::OFFramework& framework;
// Init state
virtual void init(void) override;
// Create any gauge metrics during start
virtual void createStaticGauges(void) override;
// remove any gauge metrics during stop
virtual void removeStaticGauges(void) override;
// create any gauge metric families during start
Expand Down Expand Up @@ -667,22 +670,14 @@ class AgentPrometheusManager : private PrometheusManager {
Family<Counter> *counter_ep_create_family_ptr;
// Counter family to track all EpCounter removes
Family<Counter> *counter_ep_remove_family_ptr;
// Gauge family to track the total # of EpCounters
Family<Gauge> *gauge_ep_total_family_ptr;
// Counter to track ep creates
Counter *counter_ep_create_ptr;
// Counter to track ep removes
Counter *counter_ep_remove_ptr;
// Gauge to track total Eps
Gauge *gauge_ep_total_ptr;
// Actual ep total count
double gauge_ep_total;
// func to increment EpCounter create
void incStaticCounterEpCreate(void);
// func to decrement EpCounter remove
void incStaticCounterEpRemove(void);
// func to set total EpCounter
void updateStaticGaugeEpTotal(bool add);
// create any ep gauge metric families during start
void createStaticGaugeFamiliesEp(void);
// remove any ep gauge metric families during stop
Expand All @@ -691,10 +686,6 @@ class AgentPrometheusManager : private PrometheusManager {
void createStaticCounterFamiliesEp(void);
// remove any ep counter metric families during stop
void removeStaticCounterFamiliesEp(void);
// create any ep gauge metric during start
void createStaticGaugesEp(void);
// remove any ep gauge metric during stop
void removeStaticGaugesEp(void);
// create any ep counter metric during start
void createStaticCountersEp(void);
// remove any ep counter metric during stop
Expand Down Expand Up @@ -806,23 +797,15 @@ class AgentPrometheusManager : private PrometheusManager {
Family<Counter> *counter_svc_create_family_ptr;
// Counter family to track all SvcCounter removes
Family<Counter> *counter_svc_remove_family_ptr;
// Gauge family to track the total # of SvcCounters
Family<Gauge> *gauge_svc_total_family_ptr;
// Counter to track svc creates
Counter *counter_svc_create_ptr;
// Counter to track svc removes
Counter *counter_svc_remove_ptr;
// Gauge to track total SVCs
Gauge *gauge_svc_total_ptr;
// Actual svc total count
double gauge_svc_total;

// func to increment SvcCounter create
void incStaticCounterSvcCreate(void);
// func to decrement SvcCounter remove
void incStaticCounterSvcRemove(void);
// func to set total SvcCounter
void updateStaticGaugeSvcTotal(bool add);
// create any svc gauge metric families during start
void createStaticGaugeFamiliesSvc(void);
// remove any svc gauge metric families during stop
Expand All @@ -831,10 +814,6 @@ class AgentPrometheusManager : private PrometheusManager {
void createStaticCounterFamiliesSvc(void);
// remove any svc counter metric families during stop
void removeStaticCounterFamiliesSvc(void);
// create any svc gauge metric during start
void createStaticGaugesSvc(void);
// remove any svc gauge metric during stop
void removeStaticGaugesSvc(void);
// create any svc counter metric during start
void createStaticCountersSvc(void);
// remove any svc counter metric during stop
Expand Down Expand Up @@ -1005,43 +984,51 @@ class AgentPrometheusManager : private PrometheusManager {
/* End of OFPeerStats related apis and state */


/* Start of RemoteEp related apis and state */
// Lock to safe guard RemoteEp related state
mutex remote_ep_mutex;

enum REMOTE_EP_METRICS {
REMOTE_EP_METRICS_MIN,
REMOTE_EP_COUNT = REMOTE_EP_METRICS_MIN,
REMOTE_EP_METRICS_MAX = REMOTE_EP_COUNT
/* Start of MoDBCount related apis and state */
// Lock to safe guard MoDBCount related state
mutex modb_count_mutex;

enum MODB_COUNT_METRICS {
MODB_COUNT_METRICS_MIN,
MODB_COUNT_EP_LOCAL = MODB_COUNT_METRICS_MIN,
MODB_COUNT_EP_REMOTE,
MODB_COUNT_EP_EXT,
MODB_COUNT_EPG,
MODB_COUNT_EXT_INTF,
MODB_COUNT_RD,
MODB_COUNT_SERVICE,
MODB_COUNT_CONTRACT,
MODB_COUNT_SG,
MODB_COUNT_METRICS_MAX = MODB_COUNT_SG
};

// Static Metric families and metrics
// metric families to track all RemoteEp metrics
Family<Gauge> *gauge_remote_ep_family_ptr[REMOTE_EP_METRICS_MAX+1];
// metric families to track all MoDBCount metrics
Family<Gauge> *gauge_modb_count_family_ptr[MODB_COUNT_METRICS_MAX+1];

// create any remote ep stats gauge metric families during start
void createStaticGaugeFamiliesRemoteEp(void);
// remove any remote ep stats gauge metric families during stop
void removeStaticGaugeFamiliesRemoteEp(void);
// create any modb count gauge metric families during start
void createStaticGaugeFamiliesMoDBCount(void);
// remove any modb count gauge metric families during stop
void removeStaticGaugeFamiliesMoDBCount(void);

// Dynamic Metric families and metrics
// CRUD for every Remote ep metric
// func to create gauge for remote ep given metric type
void createDynamicGaugeRemoteEp(REMOTE_EP_METRICS metric);
// CRUD for every modb count metric
// func to create gauge for modb count given metric type
void createDynamicGaugeMoDBCount(MODB_COUNT_METRICS metric);

// func to get label map and Gauge for RemoteEp given metric type
Gauge * getDynamicGaugeRemoteEp(REMOTE_EP_METRICS metric);
// func to get label map and Gauge for MoDBCount given metric type
Gauge * getDynamicGaugeMoDBCount(MODB_COUNT_METRICS metric);

// func to remove gauge for RemoteEp given metric type
bool removeDynamicGaugeRemoteEp(REMOTE_EP_METRICS metric);
// func to remove all gauges of every RemoteEp
void removeDynamicGaugeRemoteEp(void);
// func to remove gauge for MoDBCount given metric type
bool removeDynamicGaugeMoDBCount(MODB_COUNT_METRICS metric);
// func to remove all gauges of every MoDBCount
void removeDynamicGaugeMoDBCount(void);

/**
* cache Gauge ptr for every RemoteEp metric
* cache Gauge ptr for every MoDBCount metric
*/
Gauge* remote_ep_gauge_map[REMOTE_EP_METRICS_MAX+1];
/* End of RemoteEp related apis and state */
Gauge* modb_count_gauge_map[MODB_COUNT_METRICS_MAX+1];
/* End of MoDBCount related apis and state */


/* Start of RDDropCounter related apis and state */
Expand Down
10 changes: 10 additions & 0 deletions agent-ovs/lib/include/opflexagent/ServiceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ class ServiceManager : private boost::noncopyable {
void getServicesByDomain(const opflex::modb::URI& domain,
/* out */ std::unordered_set<std::string>& servs);

/**
* Get the total number of Services
*
* @return total Service MODB objects
*/
size_t getServiceCount() {
std::lock_guard<std::mutex> guard(serv_mutex);
return aserv_map.size();
}

private:
/**
* Add or update the service state with new information about an
Expand Down
Loading

0 comments on commit 5469c25

Please sign in to comment.