From b3e00b3427a8d9ec84aa4c9dca5fae3cef8a89c8 Mon Sep 17 00:00:00 2001 From: Santosh Gupta Date: Fri, 28 Oct 2016 16:28:33 -0700 Subject: [PATCH] Add node_type field and key to NodeStatus.system_mem/cpu_usage node_type field/key added. Change-Id: I8c30eefe06ff486abddc7c8df80b82b14067cbe9 Closes-Bug:1637323 (cherry picked from commit 2607b2c1d718ec30ab11c02b47e046a7742c1ea5) --- src/analytics/viz.sandesh | 10 ++++++++++ src/base/sandesh/cpuinfo.sandesh | 2 ++ src/base/sandesh/nodeinfo.sandesh | 4 ++-- .../analytics_nodemgr/analytics_event_manager.py | 3 ++- src/nodemgr/common/cpuinfo.py | 6 ++++-- src/nodemgr/common/event_manager.py | 4 ++-- src/nodemgr/config_nodemgr/config_event_manager.py | 3 ++- src/nodemgr/control_nodemgr/control_event_manager.py | 3 ++- src/nodemgr/database_nodemgr/database_event_manager.py | 3 ++- src/nodemgr/vrouter_nodemgr/vrouter_event_manager.py | 3 ++- src/sandesh/common/vns.sandesh | 9 +++++++++ 11 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/analytics/viz.sandesh b/src/analytics/viz.sandesh index 41ade474273..526cdc04c9d 100644 --- a/src/analytics/viz.sandesh +++ b/src/analytics/viz.sandesh @@ -2094,6 +2094,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_mem_usage.free', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.buffers', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.cached', 'datatype' : 'int', 'index' : false}, + { 'name' : 'system_mem_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { @@ -2107,6 +2108,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_mem_usage.free', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.buffers', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.cached', 'datatype' : 'int', 'index' : false}, + { 'name' : 'system_mem_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { @@ -2120,6 +2122,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_mem_usage.free', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.buffers', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.cached', 'datatype' : 'int', 'index' : false}, + { 'name' : 'system_mem_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { @@ -2133,6 +2136,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_mem_usage.free', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.buffers', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.cached', 'datatype' : 'int', 'index' : false}, + { 'name' : 'system_mem_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { @@ -2146,6 +2150,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_mem_usage.free', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.buffers', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_mem_usage.cached', 'datatype' : 'int', 'index' : false}, + { 'name' : 'system_mem_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { @@ -2158,6 +2163,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_cpu_usage.five_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.fifteen_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.cpu_share', 'datatype' : 'double', 'index' : true}, + { 'name' : 'system_cpu_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { @@ -2170,6 +2176,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_cpu_usage.five_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.fifteen_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.cpu_share', 'datatype' : 'double', 'index' : true}, + { 'name' : 'system_cpu_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { @@ -2182,6 +2189,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_cpu_usage.five_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.fifteen_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.cpu_share', 'datatype' : 'double', 'index' : true}, + { 'name' : 'system_cpu_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { @@ -2194,6 +2202,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_cpu_usage.five_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.fifteen_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.cpu_share', 'datatype' : 'double', 'index' : true}, + { 'name' : 'system_cpu_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { @@ -2206,6 +2215,7 @@ const list _STAT_TABLES = [ { 'name' : 'system_cpu_usage.five_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.fifteen_min_avg', 'datatype' : 'int', 'index' : false}, { 'name' : 'system_cpu_usage.cpu_share', 'datatype' : 'double', 'index' : true}, + { 'name' : 'system_cpu_usage.node_type', 'datatype' : 'string', 'index' : true}, ] }, { diff --git a/src/base/sandesh/cpuinfo.sandesh b/src/base/sandesh/cpuinfo.sandesh index f60b432ae5a..67fb6abe30e 100644 --- a/src/base/sandesh/cpuinfo.sandesh +++ b/src/base/sandesh/cpuinfo.sandesh @@ -28,6 +28,7 @@ struct SysMemInfo { 3: u32 free; 4: u32 buffers; 5: u32 cached; + 6: string node_type; } /** @@ -74,4 +75,5 @@ struct SysCpuInfo { 2: double five_min_avg; 3: double fifteen_min_avg; 4: double cpu_share; + 5: string node_type; } diff --git a/src/base/sandesh/nodeinfo.sandesh b/src/base/sandesh/nodeinfo.sandesh index 4f33bf7d90e..b150baa4bf7 100644 --- a/src/base/sandesh/nodeinfo.sandesh +++ b/src/base/sandesh/nodeinfo.sandesh @@ -38,8 +38,8 @@ struct NodeStatus { // map key is : 10: optional map process_mem_cpu_usage (tags=".__key,.cpu_share") 12: optional cpuinfo.SystemCpuInfo system_cpu_info - 13: optional cpuinfo.SysMemInfo system_mem_usage(tags="") - 14: optional cpuinfo.SysCpuInfo system_cpu_usage(tags=".cpu_share") + 13: optional cpuinfo.SysMemInfo system_mem_usage(tags=".node_type") + 14: optional cpuinfo.SysCpuInfo system_cpu_usage(tags=".node_type,.cpu_share") } /** diff --git a/src/nodemgr/analytics_nodemgr/analytics_event_manager.py b/src/nodemgr/analytics_nodemgr/analytics_event_manager.py index 979ec98a7ee..d8f47ec3cd0 100644 --- a/src/nodemgr/analytics_nodemgr/analytics_event_manager.py +++ b/src/nodemgr/analytics_nodemgr/analytics_event_manager.py @@ -20,7 +20,7 @@ from pysandesh.sandesh_base import * from sandesh_common.vns.ttypes import Module, NodeType from sandesh_common.vns.constants import ModuleNames, NodeTypeNames,\ - Module2NodeType + Module2NodeType, UVENodeTypeNames from subprocess import Popen, PIPE from nodemgr.common.sandesh.nodeinfo.ttypes import * @@ -37,6 +37,7 @@ def __init__(self, rule_file, discovery_server, self, rule_file, discovery_server, discovery_port, collector_addr, sandesh_global) self.node_type = 'contrail-analytics' + self.uve_node_type = UVENodeTypeNames[NodeType.ANALYTICS] self.table = "ObjectCollectorInfo" self.module = Module.ANALYTICS_NODE_MGR self.module_id = ModuleNames[self.module] diff --git a/src/nodemgr/common/cpuinfo.py b/src/nodemgr/common/cpuinfo.py index 3242ab35cf0..9c671aef1a2 100644 --- a/src/nodemgr/common/cpuinfo.py +++ b/src/nodemgr/common/cpuinfo.py @@ -48,7 +48,7 @@ def get_num_thread_per_core (self): return int(proc.communicate()[0]) #end get_num_thread_per_core - def get_sys_mem_info(self): + def get_sys_mem_info(self, node_type): virtmem_info = psutil.virtual_memory() sys_mem_info = SysMemInfo() sys_mem_info.total = virtmem_info.total/1024 @@ -56,16 +56,18 @@ def get_sys_mem_info(self): sys_mem_info.free = virtmem_info.free/1024 sys_mem_info.buffers = virtmem_info.buffers/1024 sys_mem_info.cached = virtmem_info.cached/1024 + sys_mem_info.node_type = node_type return sys_mem_info #end get_sys_mem_info - def get_sys_cpu_info(self): + def get_sys_cpu_info(self, node_type): cpu_load_avg = self._get_cpu_load_avg() sys_cpu_info = SysCpuInfo() sys_cpu_info.one_min_avg = cpu_load_avg.one_min_avg sys_cpu_info.five_min_avg = cpu_load_avg.five_min_avg sys_cpu_info.fifteen_min_avg = cpu_load_avg.fifteen_min_avg sys_cpu_info.cpu_share = self._get_sys_cpu_share() + sys_cpu_info.node_type = node_type return sys_cpu_info #end get_sys_cpu_info diff --git a/src/nodemgr/common/event_manager.py b/src/nodemgr/common/event_manager.py index bae0da19874..2d343c52caf 100644 --- a/src/nodemgr/common/event_manager.py +++ b/src/nodemgr/common/event_manager.py @@ -557,8 +557,8 @@ def event_tick_60(self): # get system mem/cpu usage system_mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu, self.last_time) - system_mem_usage = system_mem_cpu_usage_data.get_sys_mem_info() - system_cpu_usage = system_mem_cpu_usage_data.get_sys_cpu_info() + system_mem_usage = system_mem_cpu_usage_data.get_sys_mem_info(self.uve_node_type) + system_cpu_usage = system_mem_cpu_usage_data.get_sys_cpu_info(self.uve_node_type) # update last_cpu/time after all processing is complete self.last_cpu = system_mem_cpu_usage_data.last_cpu diff --git a/src/nodemgr/config_nodemgr/config_event_manager.py b/src/nodemgr/config_nodemgr/config_event_manager.py index 4ebefe2f191..c774c0bfce9 100644 --- a/src/nodemgr/config_nodemgr/config_event_manager.py +++ b/src/nodemgr/config_nodemgr/config_event_manager.py @@ -28,7 +28,7 @@ from pysandesh.gen_py.sandesh_trace.ttypes import SandeshTraceRequest from sandesh_common.vns.ttypes import Module, NodeType from sandesh_common.vns.constants import ModuleNames, NodeTypeNames,\ - Module2NodeType, INSTANCE_ID_DEFAULT + Module2NodeType, INSTANCE_ID_DEFAULT, UVENodeTypeNames from subprocess import Popen, PIPE from StringIO import StringIO @@ -44,6 +44,7 @@ def __init__(self, rule_file, discovery_server, cassandra_repair_interval, cassandra_repair_logdir): self.node_type = "contrail-config" + self.uve_node_type = UVENodeTypeNames[NodeType.CONFIG] self.table = "ObjectConfigNode" self.module = Module.CONFIG_NODE_MGR self.module_id = ModuleNames[self.module] diff --git a/src/nodemgr/control_nodemgr/control_event_manager.py b/src/nodemgr/control_nodemgr/control_event_manager.py index a346b9593df..02f739981e0 100644 --- a/src/nodemgr/control_nodemgr/control_event_manager.py +++ b/src/nodemgr/control_nodemgr/control_event_manager.py @@ -27,7 +27,7 @@ from pysandesh.gen_py.sandesh_trace.ttypes import SandeshTraceRequest from sandesh_common.vns.ttypes import Module, NodeType from sandesh_common.vns.constants import ModuleNames, NodeTypeNames,\ - Module2NodeType, INSTANCE_ID_DEFAULT + Module2NodeType, INSTANCE_ID_DEFAULT, UVENodeTypeNames from subprocess import Popen, PIPE from StringIO import StringIO @@ -41,6 +41,7 @@ class ControlEventManager(EventManager): def __init__(self, rule_file, discovery_server, discovery_port, collector_addr): self.node_type = "contrail-control" + self.uve_node_type = UVENodeTypeNames[NodeType.CONTROL] self.table = "ObjectBgpRouter" self.module = Module.CONTROL_NODE_MGR self.module_id = ModuleNames[self.module] diff --git a/src/nodemgr/database_nodemgr/database_event_manager.py b/src/nodemgr/database_nodemgr/database_event_manager.py index 0dab0bd2953..9c8368662b5 100644 --- a/src/nodemgr/database_nodemgr/database_event_manager.py +++ b/src/nodemgr/database_nodemgr/database_event_manager.py @@ -32,7 +32,7 @@ from sandesh_common.vns.ttypes import Module, NodeType from sandesh_common.vns.constants import ModuleNames, NodeTypeNames,\ Module2NodeType, INSTANCE_ID_DEFAULT, SERVICE_CONTRAIL_DATABASE, \ - RepairNeededKeyspaces, ThreadPoolNames + RepairNeededKeyspaces, ThreadPoolNames, UVENodeTypeNames from subprocess import Popen, PIPE from StringIO import StringIO @@ -52,6 +52,7 @@ def __init__(self, rule_file, discovery_server, cassandra_repair_interval, cassandra_repair_logdir): self.node_type = "contrail-database" + self.uve_node_type = UVENodeTypeNames[NodeType.DATABASE] self.table = "ObjectDatabaseInfo" self.module = Module.DATABASE_NODE_MGR self.module_id = ModuleNames[self.module] diff --git a/src/nodemgr/vrouter_nodemgr/vrouter_event_manager.py b/src/nodemgr/vrouter_nodemgr/vrouter_event_manager.py index 76c4d0efedf..4a82f23c816 100644 --- a/src/nodemgr/vrouter_nodemgr/vrouter_event_manager.py +++ b/src/nodemgr/vrouter_nodemgr/vrouter_event_manager.py @@ -30,7 +30,7 @@ from pysandesh.gen_py.sandesh_trace.ttypes import SandeshTraceRequest from sandesh_common.vns.ttypes import Module, NodeType from sandesh_common.vns.constants import ModuleNames, NodeTypeNames,\ - Module2NodeType, INSTANCE_ID_DEFAULT + Module2NodeType, INSTANCE_ID_DEFAULT, UVENodeTypeNames from subprocess import Popen, PIPE from StringIO import StringIO @@ -55,6 +55,7 @@ def __init__(self, rule_file, discovery_server, EventManager.__init__(self, rule_file, discovery_server, discovery_port, collector_addr, sandesh_global) self.node_type = "contrail-vrouter" + self.uve_node_type = UVENodeTypeNames[NodeType.COMPUTE] self.table = "ObjectVRouter" _disc = self.get_discovery_client() sandesh_global.init_generator( diff --git a/src/sandesh/common/vns.sandesh b/src/sandesh/common/vns.sandesh index 9ecee1597c4..34d31b452ed 100644 --- a/src/sandesh/common/vns.sandesh +++ b/src/sandesh/common/vns.sandesh @@ -333,6 +333,15 @@ enum NodeType { SERVERMGR, } +const map UVENodeTypeNames = { + NodeType.INVALID : "Invalid", + NodeType.CONFIG : "config-node", + NodeType.CONTROL : "control-node", + NodeType.ANALYTICS : "analytics-node", + NodeType.COMPUTE : "vrouter", + NodeType.DATABASE : "database-node", +} + const map NodeTypeNames = { NodeType.INVALID : "Invalid", NodeType.CONFIG : "Config",