From 364a065078a1adaf892738a1a3dbe55fe48b15e2 Mon Sep 17 00:00:00 2001 From: Jamo Luhrsen Date: Thu, 14 Apr 2016 23:40:53 -0700 Subject: [PATCH] add ability to poll on Operational store. default still remains Config store, but "-d Operational" will change to poll on the Operational store. Change-Id: I384104473db384577452fdeafc7c764d329cd6b8 Signed-off-by: Jamo Luhrsen --- tools/clustering/cluster-monitor/monitor.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/clustering/cluster-monitor/monitor.py b/tools/clustering/cluster-monitor/monitor.py index d708ea7252..d6ef370031 100644 --- a/tools/clustering/cluster-monitor/monitor.py +++ b/tools/clustering/cluster-monitor/monitor.py @@ -5,7 +5,7 @@ Author: Phillip Shea Updated: 2016-Mar-07 This tool provides real-time visualization of the cluster member roles for all -shards in the config datastore. +shards in either the config or operational datastore. A file named 'cluster.json' contaning a list of the IP addresses and port numbers of the controllers is required. This resides in the same directory as monitor.py. @@ -25,7 +25,7 @@ needed for other apps in this folder. The file should look like this: } } -Usage:python monitor.py +Usage:python monitor.py [-d data_store_name] """ from io import BytesIO import time @@ -35,6 +35,7 @@ import sys import json import pycurl import string +import argparse def rest_get(restURL, username, password): @@ -60,7 +61,7 @@ def getClusterRolesWithCurl(shardName, *args): controller_state[controller["ip"]] = None url = "http://" + controller["ip"] + ":" + controller["port"] + "/jolokia/read/org.opendaylight.controller:" url += 'Category=Shards,name=' + names[i] - url += '-shard-' + shardName + '-config,type=DistributedConfigDatastore' + url += '-shard-' + shardName + '-' + data_store.lower() + ',type=Distributed' + data_store + 'Datastore' try: resp = rest_get(url, username, password) if resp['status'] != 200: @@ -94,6 +95,15 @@ def size_and_color(cluster_roles, field_length, ip_addr): return status_dict +parser = argparse.ArgumentParser() +parser.add_argument('-d', '--datastore', default='Config', type=str, + help='polling can be done on "Config" or "Operational" data stores') +args = parser.parse_args() +data_store = args.datastore +if data_store != 'Config' and data_store != 'Operational': + print 'Only "Config" or "Operational" data store is available for polling' + exit(1) + try: with open('cluster.json') as cluster_file: data = json.load(cluster_file) @@ -116,7 +126,8 @@ Shards = set() # Retrieve controller names and shard names. for controller in controllers: url = "http://" + controller["ip"] + ":" + controller["port"] + "/jolokia/read/org.opendaylight.controller:" - url += "Category=ShardManager,name=shard-manager-config,type=DistributedConfigDatastore" + url += "Category=ShardManager,name=shard-manager-" + data_store.lower()\ + + ",type=Distributed" + data_store + "Datastore" rest_get(url, username, password) try: data = rest_get(url, username, password) @@ -137,7 +148,7 @@ for controller in controllers: # collect shards found in any controller; does not require all controllers to have the same shards for localShard in data['value']['LocalShards']: - shardName = localShard[(localShard.find("-shard-") + 7):localShard.find("-config")] + shardName = localShard[(localShard.find("-shard-") + 7):localShard.find("-" + data_store.lower())] if shardName not in shards_to_exclude: Shards.add(shardName) print controller_names -- 2.36.6