Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 8cc1d14

Browse files
author
Michael Smith
committed
Added a show stats command to the CLI for endpoint event counts. Reduced log message sizes
1 parent 0465140 commit 8cc1d14

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

applications/multisite/intersite.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ class EndpointHandler(object):
115115
"""
116116
def __init__(self):
117117
self.db = {} # Indexed by remote site
118+
self.endpoint_add_events = 0
119+
self.endpoint_del_events = 0
118120

119121
def _remove_queued_endpoint(self, remote_site, l3out_policy, endpoint):
120122
if remote_site not in self.db:
@@ -205,7 +207,7 @@ def _merge_tenant_json(self, remote_site, new_json):
205207
l3out['l3extOut']['children'].append(new_l3instp)
206208

207209
def add_endpoint(self, endpoint, local_site):
208-
logging.info('EndpointHandler:add_endpoint endpoint: %s', endpoint.mac)
210+
logging.info('endpoint: %s', endpoint.mac)
209211
epg = endpoint.get_parent()
210212
app = epg.get_parent()
211213
tenant = app.get_parent()
@@ -220,6 +222,12 @@ def add_endpoint(self, endpoint, local_site):
220222
logging.info('Ignoring endpoint as there is no policy defined for its EPG')
221223
return
222224

225+
# Track the number of endpoint events
226+
if endpoint.is_deleted():
227+
self.endpoint_del_events += 1
228+
else:
229+
self.endpoint_add_events += 1
230+
223231
# Process the endpoint policy
224232
for remote_site_policy in policy.get_site_policies():
225233
for l3out_policy in remote_site_policy.get_interfaces():
@@ -238,7 +246,7 @@ def push_to_remote_sites(self, collector):
238246
"""
239247
Push the endpoints to the remote sites
240248
"""
241-
logging.debug('EndpointHandler:push_to_remote_sites')
249+
logging.debug('')
242250
for remote_site in self.db:
243251
remote_site_obj = collector.get_site(remote_site)
244252
assert remote_site_obj is not None
@@ -342,7 +350,7 @@ def verify_endpoints(self, export_policy):
342350
logging.warning('Could not push modified entry to remote site %s %s', resp, resp.text)
343351

344352
def handle_existing_endpoints(self, policy):
345-
logging.info('handle_existing_endpoints for tenant: %s app_name: %s epg_name: %s',
353+
logging.info('for tenant: %s app_name: %s epg_name: %s',
346354
policy.tenant, policy.app, policy.epg)
347355
endpoints = Endpoint.get_all_by_epg(self._session,
348356
policy.tenant, policy.app, policy.epg,
@@ -356,7 +364,7 @@ def handle_endpoint_event(self):
356364
num_eps = MAX_ENDPOINTS
357365
while Endpoint.has_events(self._session) and num_eps:
358366
ep = Endpoint.get_event(self._session, with_relations=False)
359-
logging.info('handle_endpoint_event for Endpoint: %s', ep.mac)
367+
logging.info('for Endpoint: %s', ep.mac)
360368
self._endpoints.add_endpoint(ep, self._local_site)
361369
num_eps -= 1
362370
self._endpoints.push_to_remote_sites(self._my_collector)
@@ -784,7 +792,7 @@ def start(self):
784792
return resp
785793

786794
def remove_stale_entries(self, policy):
787-
logging.info('remove_stale_entries')
795+
logging.info('')
788796
# Get all of the local APIC entries
789797
endpoints = Endpoint.get_all_by_epg(self.session,
790798
policy.tenant, policy.app, policy.epg,
@@ -826,7 +834,7 @@ def remove_stale_entries(self, policy):
826834
l3out_mac, l3out.name, site.name)
827835

828836
def add_policy(self, policy):
829-
logging.info('add_policy')
837+
logging.info('')
830838
old_policy = self.get_policy_for_epg(policy.tenant,
831839
policy.app,
832840
policy.epg)
@@ -837,12 +845,8 @@ def add_policy(self, policy):
837845
self.remove_stale_entries(policy)
838846
self.monitor.handle_existing_endpoints(policy)
839847

840-
def validate_policy(self, policy):
841-
logging.warning('validate_policy needs to be implemented')
842-
pass
843-
844848
def remove_policy(self, policy):
845-
logging.info('remove_policy')
849+
logging.info('')
846850
self.policy_db.remove(policy)
847851

848852
def get_policy_for_epg(self, tenant_name, app_name, epg_name):
@@ -926,7 +930,7 @@ def get_num_sites(self):
926930
return len(self.sites)
927931

928932
def add_site(self, name, credentials, local):
929-
logging.info('add_site name:%s local:%s', name, local)
933+
logging.info('name:%s local:%s', name, local)
930934
self.delete_site(name)
931935
if local:
932936
site = LocalSite(name, credentials, self)
@@ -951,7 +955,7 @@ def add_site_from_config(self, site):
951955
self.add_site(site.name, creds, is_local)
952956

953957
def delete_site(self, name):
954-
logging.info('delete_site name:%s', name)
958+
logging.info('name:%s', name)
955959
for site in self.sites:
956960
if name == site.name:
957961
site.shutdown()
@@ -1001,7 +1005,7 @@ def _reload_sites(self, old_config, new_config):
10011005
return added_local_site
10021006

10031007
def reload_config(self):
1004-
logging.info('reload_config')
1008+
logging.info('')
10051009
with open(self.config_filename) as config_file:
10061010
new_config = json.load(config_file)
10071011
if 'config' not in new_config:
@@ -1059,7 +1063,7 @@ def remove_all_entries_for_policy(self, export_policy):
10591063
site_obj.remove_all_entries(str(itag), l3out.name, l3out.tenant)
10601064

10611065
def save_config(self, config):
1062-
logging.info('save_config')
1066+
logging.info('')
10631067
try:
10641068
new_config = IntersiteConfiguration(config)
10651069
except ValueError as e:
@@ -1093,7 +1097,7 @@ class CommandLine(cmd.Cmd):
10931097
prompt = 'intersite> '
10941098
intro = 'Cisco ACI Intersite tool (type help for commands)'
10951099

1096-
SHOW_CMDS = ['configfile', 'debug', 'config']
1100+
SHOW_CMDS = ['configfile', 'debug', 'config', 'stats']
10971101
DEBUG_CMDS = ['verbose', 'warnings', 'critical']
10981102

10991103
def __init__(self, collector):
@@ -1122,6 +1126,10 @@ def do_show(self, keyword):
11221126
print 'Configuration file is set to:', self.collector.config_filename
11231127
elif keyword == 'config':
11241128
print json.dumps(self.collector.config.get_config(), indent=4, separators=(',', ':'))
1129+
elif keyword == 'stats':
1130+
handler = self.collector.get_local_site().monitor._endpoints
1131+
print 'Endpoint addition events:', handler.endpoint_add_events
1132+
print 'Endpoint deletion events:', handler.endpoint_del_events
11251133

11261134
def emptyline(self):
11271135
pass

0 commit comments

Comments
 (0)