From 8b07896d47ef6fd1f599d57b1599fbb2cf62a556 Mon Sep 17 00:00:00 2001 From: hsiang41 Date: Wed, 20 Jun 2018 11:25:01 +0800 Subject: [PATCH] :Change fields type Change agenthost field type from tag to field Signed-off-by: Rick Chen rick.chen@prophetstor.com --- .../agent/metrics/ceph_cluster.py | 4 +-- .../diskprediction/agent/metrics/ceph_mon.py | 4 +-- .../diskprediction/agent/metrics/ceph_osd.py | 4 +-- .../diskprediction/agent/metrics/ceph_pool.py | 4 +-- .../diskprediction/agent/metrics/db_relay.py | 32 +++++++++---------- .../agent/metrics/sai_cluster.py | 4 +-- .../diskprediction/agent/metrics/sai_disk.py | 4 +-- .../agent/metrics/sai_disk_smart.py | 4 +-- .../diskprediction/agent/metrics/sai_host.py | 15 +++++---- .../mgr/diskprediction/common/cypher.py | 6 ++-- .../mgr/diskprediction/models/metrics/dp.py | 25 ++++++++------- 11 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/pybind/mgr/diskprediction/agent/metrics/ceph_cluster.py b/src/pybind/mgr/diskprediction/agent/metrics/ceph_cluster.py index 38edb4441ea731..8203d62c8d4f33 100644 --- a/src/pybind/mgr/diskprediction/agent/metrics/ceph_cluster.py +++ b/src/pybind/mgr/diskprediction/agent/metrics/ceph_cluster.py @@ -17,9 +17,9 @@ def _collect_data(self): c_data = Ceph_Cluster() c_data.tags['cluster_id'] = cluster_id - c_data.tags['agenthost'] = socket.gethostname() + c_data.fields['agenthost'] = socket.gethostname() c_data.tags['agenthost_domain_id'] = \ - "%s_%s" % (cluster_id, c_data.tags['agenthost']) + "%s_%s" % (cluster_id, c_data.fields['agenthost']) c_data.fields['osd_epoch'] = obj_api.get_osd_epoch() c_data.fields['num_osd'] = obj_api.get_max_osd() c_data.fields['num_mon'] = len(obj_api.get_mons()) diff --git a/src/pybind/mgr/diskprediction/agent/metrics/ceph_mon.py b/src/pybind/mgr/diskprediction/agent/metrics/ceph_mon.py index 3e409a478810c5..c486caa5d9b0ef 100644 --- a/src/pybind/mgr/diskprediction/agent/metrics/ceph_mon.py +++ b/src/pybind/mgr/diskprediction/agent/metrics/ceph_mon.py @@ -24,9 +24,9 @@ def _collect_data(self): d_mon = Ceph_MON() d_mon.tags['cluster_id'] = cluster_id d_mon.tags['mon_id'] = n_name[4:] - d_mon.tags['agenthost'] = socket.gethostname() + d_mon.fields['agenthost'] = socket.gethostname() d_mon.tags['agenthost_domain_id'] = \ - "%s_%s" % (cluster_id, d_mon.tags['agenthost']) + "%s_%s" % (cluster_id, d_mon.fields['agenthost']) d_mon.fields['num_sessions'] = \ i_perf.get("mon.num_sessions", {}).get('value', 0) d_mon.fields['session_add'] = \ diff --git a/src/pybind/mgr/diskprediction/agent/metrics/ceph_osd.py b/src/pybind/mgr/diskprediction/agent/metrics/ceph_osd.py index 6e43cc603c6a96..eb957f6bfd4743 100644 --- a/src/pybind/mgr/diskprediction/agent/metrics/ceph_osd.py +++ b/src/pybind/mgr/diskprediction/agent/metrics/ceph_osd.py @@ -26,9 +26,9 @@ def _collect_data(self): stat_bytes_used = 0 d_osd.tags['cluster_id'] = cluster_id d_osd.tags['osd_id'] = n_name[4:] - d_osd.tags['agenthost'] = socket.gethostname() + d_osd.fields['agenthost'] = socket.gethostname() d_osd.tags['agenthost_domain_id'] = \ - '%s_%s' % (cluster_id, d_osd.tags['agenthost']) + '%s_%s' % (cluster_id, d_osd.fields['agenthost']) d_osd.tags['host_domain_id'] = \ '%s_%s' % (cluster_id, obj_api.get_osd_hostname(d_osd.tags['osd_id'])) diff --git a/src/pybind/mgr/diskprediction/agent/metrics/ceph_pool.py b/src/pybind/mgr/diskprediction/agent/metrics/ceph_pool.py index 802439df2c04d2..51506ece67e050 100644 --- a/src/pybind/mgr/diskprediction/agent/metrics/ceph_pool.py +++ b/src/pybind/mgr/diskprediction/agent/metrics/ceph_pool.py @@ -21,9 +21,9 @@ def _collect_data(self): p_id = pool.get("id") d_pool.tags['cluster_id'] = cluster_id d_pool.tags['pool_id'] = p_id - d_pool.tags['agenthost'] = socket.gethostname() + d_pool.fields['agenthost'] = socket.gethostname() d_pool.tags['agenthost_domain_id'] = \ - "%s_%s" % (cluster_id, d_pool.tags['agenthost']) + "%s_%s" % (cluster_id, d_pool.fields['agenthost']) d_pool.fields['pool_name'] = p_name d_pool.fields['bytes_used'] = \ pool.get('stats', {}).get('bytes_used', 0) diff --git a/src/pybind/mgr/diskprediction/agent/metrics/db_relay.py b/src/pybind/mgr/diskprediction/agent/metrics/db_relay.py index af5bb05419554d..f194f623eb4fec 100644 --- a/src/pybind/mgr/diskprediction/agent/metrics/db_relay.py +++ b/src/pybind/mgr/diskprediction/agent/metrics/db_relay.py @@ -110,9 +110,9 @@ def _cluster_contains_host(self): 'CephClusterContainsHost' ) cluster_host = socket.gethostname() - data.tags['agenthost'] = cluster_host + data.fields['agenthost'] = cluster_host data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['host'] = cluster_host data.fields['cmd'] = str(cypher_cmd) self._host_nodes[host] = host_node @@ -153,9 +153,9 @@ def _host_contains_mon(self): 'HostContainsMon' ) cluster_host = socket.gethostname() - data.tags['agenthost'] = cluster_host + data.fields['agenthost'] = cluster_host data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['host'] = cluster_host data.fields['cmd'] = str(cypher_cmd) self.data.append(data) @@ -249,9 +249,9 @@ def _host_contains_osd(self): 'HostContainsOsd' ) cluster_host = socket.gethostname() - data.tags['agenthost'] = cluster_host + data.fields['agenthost'] = cluster_host data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['host'] = cluster_host data.fields['cmd'] = str(cypher_cmd) self._osd_nodes[str(osd_id)] = osd_node @@ -297,9 +297,9 @@ def _host_contains_mds(self): 'HostContainsMds' ) cluster_host = socket.gethostname() - data.tags['agenthost'] = cluster_host + data.fields['agenthost'] = cluster_host data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['host'] = cluster_host data.fields['cmd'] = str(cypher_cmd) self.data.append(data) @@ -353,9 +353,9 @@ def _osd_contains_pg(self): 'OsdContainsPg' ) cluster_host = socket.gethostname() - data.tags['agenthost'] = cluster_host + data.fields['agenthost'] = cluster_host data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['host'] = cluster_host data.fields['cmd'] = str(cypher_cmd) self.data.append(data) @@ -416,9 +416,9 @@ def _osd_contains_disk(self): 'DiskOfOsd' ) cluster_host = socket.gethostname() - data.tags['agenthost'] = cluster_host + data.fields['agenthost'] = cluster_host data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['host'] = cluster_host data.fields['cmd'] = str(cypher_cmd) self.data.append(data) @@ -438,9 +438,9 @@ def _osd_contains_disk(self): disk_node, 'VmHostContainsVmDisk' ) - data.tags['agenthost'] = cluster_host + data.fields['agenthost'] = cluster_host data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['host'] = cluster_host data.fields['cmd'] = str(cypher_cmd) self.data.append(data) @@ -528,9 +528,9 @@ def _rbd_contains_pg(self): 'RbdContainsPg' ) cluster_host = socket.gethostname() - data.tags['agenthost'] = cluster_host + data.fields['agenthost'] = cluster_host data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['host'] = cluster_host data.fields['cmd'] = str(cypher_cmd) self.data.append(data) diff --git a/src/pybind/mgr/diskprediction/agent/metrics/sai_cluster.py b/src/pybind/mgr/diskprediction/agent/metrics/sai_cluster.py index cf9e83edcdfffd..24cb66da9d91b2 100644 --- a/src/pybind/mgr/diskprediction/agent/metrics/sai_cluster.py +++ b/src/pybind/mgr/diskprediction/agent/metrics/sai_cluster.py @@ -18,8 +18,8 @@ def _collect_data(self): c_data.tags['domain_id'] = str(cluster_id) c_data.fields['agent_version'] = AGENT_VERSION c_data.fields['host_domain_id'] = "%s_%s" % (str(cluster_id), str(socket.gethostname())) - c_data.tags['agenthost'] = str(socket.gethostname()) + c_data.fields['agenthost'] = str(socket.gethostname()) c_data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, c_data.tags['agenthost'])) + str("%s_%s" % (cluster_id, c_data.fields['agenthost'])) c_data.fields['name'] = 'ceph mgr plugin' self.data.append(c_data) diff --git a/src/pybind/mgr/diskprediction/agent/metrics/sai_disk.py b/src/pybind/mgr/diskprediction/agent/metrics/sai_disk.py index 555df8f3fb8f27..0d0cb4aacfd9af 100644 --- a/src/pybind/mgr/diskprediction/agent/metrics/sai_disk.py +++ b/src/pybind/mgr/diskprediction/agent/metrics/sai_disk.py @@ -66,9 +66,9 @@ def _collect_data(self): d_data.fields['host_domain_id'] = \ str("%s_%s" % (cluster_id, osds_meta.get("hostname", "None"))) - d_data.tags['agenthost'] = str(socket.gethostname()) + d_data.fields['agenthost'] = str(socket.gethostname()) d_data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, d_data.tags['agenthost'])) + str("%s_%s" % (cluster_id, d_data.fields['agenthost'])) serial_number = s_val.get("serial_number") wwn = s_val.get("wwn", {}) wwpn = '' diff --git a/src/pybind/mgr/diskprediction/agent/metrics/sai_disk_smart.py b/src/pybind/mgr/diskprediction/agent/metrics/sai_disk_smart.py index 171dabf621109c..df5c3128937a2c 100644 --- a/src/pybind/mgr/diskprediction/agent/metrics/sai_disk_smart.py +++ b/src/pybind/mgr/diskprediction/agent/metrics/sai_disk_smart.py @@ -31,9 +31,9 @@ def _collect_data(self): smart_data.fields['host_domain_id'] = \ str('%s_%s' % (cluster_id, osds_meta.get('hostname', 'None'))) - smart_data.tags['agenthost'] = str(socket.gethostname()) + smart_data.fields['agenthost'] = str(socket.gethostname()) smart_data.tags['agenthost_domain_id'] = \ - str('%s_%s' % (cluster_id, smart_data.tags['agenthost'])) + str('%s_%s' % (cluster_id, smart_data.fields['agenthost'])) # parse attributes ata_smart = s_val.get('ata_smart_attributes', {}) for attr in ata_smart.get('attrs', []): diff --git a/src/pybind/mgr/diskprediction/agent/metrics/sai_host.py b/src/pybind/mgr/diskprediction/agent/metrics/sai_host.py index 8c3407b671079b..b40d5384377c1a 100644 --- a/src/pybind/mgr/diskprediction/agent/metrics/sai_host.py +++ b/src/pybind/mgr/diskprediction/agent/metrics/sai_host.py @@ -2,7 +2,7 @@ import socket -from . import MetricsAgent +from . import MetricsAgent, AGENT_VERSION from ...common.db import DB_API from ...models.metrics.dp import SAI_Host @@ -25,9 +25,9 @@ def _collect_data(self): osd_host = osd_metadata.get("hostname", "None") if osd_host not in hosts: data = SAI_Host() - data.tags['agenthost'] = str(socket.gethostname()) + data.fields['agenthost'] = str(socket.gethostname()) data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['domain_id'] = \ str("%s_%s" % (cluster_id, osd_host)) data.fields['cluster_domain_id'] = str(cluster_id) @@ -48,9 +48,9 @@ def _collect_data(self): mon_addr = _data['public_addr'].split(':')[0] if mon_host not in hosts: data = SAI_Host() - data.tags['agenthost'] = str(socket.gethostname()) + data.fields['agenthost'] = str(socket.gethostname()) data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['domain_id'] = \ str("%s_%s" % (cluster_id, mon_host)) data.fields['cluster_domain_id'] = str(cluster_id) @@ -70,9 +70,10 @@ def _collect_data(self): mds_host = mds_data.get('name') if mds_host not in hosts: data = SAI_Host() - data.tags['agenthost'] = str(socket.gethostname()) + data.fields['agent_version'] = AGENT_VERSION + data.fields['agenthost'] = str(socket.gethostname()) data.tags['agenthost_domain_id'] = \ - str("%s_%s" % (cluster_id, data.tags['agenthost'])) + str("%s_%s" % (cluster_id, data.fields['agenthost'])) data.tags['domain_id'] = \ str("%s_%s" % (cluster_id, mds_host)) data.fields['cluster_domain_id'] = str(cluster_id) diff --git a/src/pybind/mgr/diskprediction/common/cypher.py b/src/pybind/mgr/diskprediction/common/cypher.py index 4ee9357134cf2f..89d54cc3beceb9 100644 --- a/src/pybind/mgr/diskprediction/common/cypher.py +++ b/src/pybind/mgr/diskprediction/common/cypher.py @@ -22,7 +22,7 @@ def update(node, key, value, timestamp=int(time.time()*(1000**3))): if key != "time": cy_value = "\'%s\'" % value else: - cy_value=value + cy_value = value result = \ "set %s.%s=case when %s.time >= %s then %s.%s ELSE %s end" % ( node.label, key, @@ -56,8 +56,10 @@ def create_or_merge(node, timestamp=int(time.time()*(1000**3))): return result @staticmethod - def add_link(snode, dnode, relationship, timestamp=int(time.time()*(1000**3))): + def add_link(snode, dnode, relationship, timestamp=None): result = "" + if timestamp is None: + timestamp = int(time.time()*(1000**3)) if isinstance(snode, NodeInfo) and isinstance(dnode, NodeInfo): cy_snode = CypherOP.create_or_merge(snode, timestamp) cy_dnode = CypherOP.create_or_merge(dnode, timestamp) diff --git a/src/pybind/mgr/diskprediction/models/metrics/dp.py b/src/pybind/mgr/diskprediction/models/metrics/dp.py index 15a026457fc53e..a3439b0d323b19 100644 --- a/src/pybind/mgr/diskprediction/models/metrics/dp.py +++ b/src/pybind/mgr/diskprediction/models/metrics/dp.py @@ -9,7 +9,7 @@ class CPU(MetricsField): def __init__(self): super(CPU, self).__init__() - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.tags['cpu'] = None self.fields['usage_guest'] = None @@ -33,7 +33,7 @@ class DiskIO(MetricsField): def __init__(self): super(DiskIO, self).__init__() - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.tags['name'] = None self.fields['reads'] = None @@ -56,7 +56,7 @@ class MEM(MetricsField): def __init__(self): super(MEM, self).__init__() - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.fields['active'] = None self.fields['available'] = None @@ -79,7 +79,7 @@ class NET(MetricsField): def __init__(self): super(NET, self).__init__() - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.tags['interface'] = None self.fields['bytes_recv'] = None @@ -102,7 +102,8 @@ class SAI_Host(MetricsField): def __init__(self): super(SAI_Host, self).__init__() self.tags['domain_id'] = None - self.tags['agenthost'] = None + self.fields['agenthost'] = None + self.fields['agent_version'] = None self.tags['agenthost_domain_id'] = None self.fields['cluster_domain_id'] = None self.fields['name'] = None @@ -133,7 +134,7 @@ class SAI_Disk(MetricsField): def __init__(self): super(SAI_Disk, self).__init__() - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.tags['disk_domain_id'] = None self.tags['disk_name'] = None @@ -167,7 +168,7 @@ class SAI_Disk_Smart(MetricsField): def __init__(self): super(SAI_Disk_Smart, self).__init__() - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.tags['disk_domain_id'] = None self.tags['disk_name'] = None @@ -188,7 +189,7 @@ class Ceph_Cluster(MetricsField): def __init__(self): super(Ceph_Cluster, self).__init__() self.tags['cluster_id'] = None - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.fields['num_mon'] = None self.fields['num_mon_quorum'] = None @@ -223,7 +224,7 @@ def __init__(self): super(Ceph_MON, self).__init__() self.tags['cluster_id'] = None self.tags['mon_id'] = None - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.fields['num_sessions'] = None self.fields['session_add'] = None @@ -243,7 +244,7 @@ def __init__(self): super(Ceph_Pool, self).__init__() self.tags['cluster_id'] = None self.tags['pool_id'] = None - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.fields['bytes_used'] = None self.fields['max_avail'] = None @@ -262,7 +263,7 @@ def __init__(self): super(Ceph_OSD, self).__init__() self.tags['cluster_id'] = None self.tags['osd_id'] = None - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.tags['host_domain_id'] = None self.fields['op_w'] = None @@ -294,7 +295,7 @@ class DB_Relay(MetricsField): def __init__(self): super(DB_Relay, self).__init__() - self.tags['agenthost'] = None + self.fields['agenthost'] = None self.tags['agenthost_domain_id'] = None self.tags['dc_tag'] = 'na' self.tags['host'] = None