2021-09-17 13:19:49 +08:00
|
|
|
import ujson
|
2021-09-18 10:41:50 +08:00
|
|
|
import json
|
2021-09-17 13:19:49 +08:00
|
|
|
from pymilvus.grpc_gen import milvus_pb2 as milvus_types
|
|
|
|
from pymilvus import connections
|
2024-05-13 19:35:32 +08:00
|
|
|
from utils.util_log import test_log as log
|
2024-05-31 13:55:52 +08:00
|
|
|
from utils.util_log import test_log as log
|
2021-09-17 13:19:49 +08:00
|
|
|
sys_info_req = ujson.dumps({"metric_type": "system_info"})
|
|
|
|
sys_statistics_req = ujson.dumps({"metric_type": "system_statistics"})
|
|
|
|
sys_logs_req = ujson.dumps({"metric_type": "system_logs"})
|
|
|
|
|
|
|
|
|
|
|
|
class MilvusSys:
|
2021-10-21 19:08:45 +08:00
|
|
|
def __init__(self, alias='default'):
|
2021-09-17 13:19:49 +08:00
|
|
|
self.alias = alias
|
2022-04-07 10:37:31 +08:00
|
|
|
self.handler = connections._fetch_handler(alias=self.alias)
|
|
|
|
if self.handler is None:
|
2021-09-17 13:19:49 +08:00
|
|
|
raise Exception(f"Connection {alias} is disconnected or nonexistent")
|
|
|
|
|
2021-10-09 18:05:40 +08:00
|
|
|
# TODO: for now it only supports non_orm style API for getMetricsRequest
|
2022-04-07 10:37:31 +08:00
|
|
|
req = milvus_types.GetMetricsRequest(request=sys_info_req)
|
2024-05-31 13:55:52 +08:00
|
|
|
self.sys_info = self.handler._stub.GetMetrics(req, wait_for_ready=True, timeout=None)
|
|
|
|
# req = milvus_types.GetMetricsRequest(request=sys_statistics_req)
|
|
|
|
# self.sys_statistics = self.handler._stub.GetMetrics(req, wait_for_ready=True, timeout=None)
|
|
|
|
# req = milvus_types.GetMetricsRequest(request=sys_logs_req)
|
|
|
|
# self.sys_logs = self.handler._stub.GetMetrics(req, wait_for_ready=True, timeout=None)
|
2024-05-14 10:29:32 +08:00
|
|
|
self.sys_info = self.handler._stub.GetMetrics(req, wait_for_ready=True, timeout=60)
|
2024-05-13 19:35:32 +08:00
|
|
|
log.debug(f"sys_info: {self.sys_info}")
|
2021-09-17 13:19:49 +08:00
|
|
|
|
2024-05-31 13:55:52 +08:00
|
|
|
def refresh(self):
|
|
|
|
req = milvus_types.GetMetricsRequest(request=sys_info_req)
|
|
|
|
self.sys_info = self.handler._stub.GetMetrics(req, wait_for_ready=True, timeout=None)
|
|
|
|
# req = milvus_types.GetMetricsRequest(request=sys_statistics_req)
|
|
|
|
# self.sys_statistics = self.handler._stub.GetMetrics(req, wait_for_ready=True, timeout=None)
|
|
|
|
# req = milvus_types.GetMetricsRequest(request=sys_logs_req)
|
|
|
|
# self.sys_logs = self.handler._stub.GetMetrics(req, wait_for_ready=True, timeout=None)
|
|
|
|
log.debug(f"sys info response: {self.sys_info.response}")
|
|
|
|
|
|
|
|
|
2021-09-17 13:19:49 +08:00
|
|
|
@property
|
|
|
|
def build_version(self):
|
2021-09-22 16:26:30 +08:00
|
|
|
"""get the first node's build version as milvus build version"""
|
2021-09-18 10:41:50 +08:00
|
|
|
return self.nodes[0].get('infos').get('system_info').get('system_version')
|
2021-09-17 13:19:49 +08:00
|
|
|
|
2022-05-18 17:56:02 +08:00
|
|
|
@property
|
|
|
|
def build_time(self):
|
|
|
|
"""get the first node's build time as milvus build time"""
|
|
|
|
return self.nodes[0].get('infos').get('system_info').get('build_time')
|
|
|
|
|
2021-09-17 13:19:49 +08:00
|
|
|
@property
|
|
|
|
def deploy_mode(self):
|
2021-09-22 16:26:30 +08:00
|
|
|
"""get the first node's deploy_mode as milvus deploy_mode"""
|
2021-09-18 10:41:50 +08:00
|
|
|
return self.nodes[0].get('infos').get('system_info').get('deploy_mode')
|
2021-09-17 13:19:49 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def simd_type(self):
|
2021-10-01 20:45:36 +08:00
|
|
|
"""
|
|
|
|
get simd type that milvus is running against
|
|
|
|
return the first query node's simd type
|
|
|
|
"""
|
2022-05-18 17:56:02 +08:00
|
|
|
for node in self.query_nodes:
|
|
|
|
return node.get('infos').get('system_configurations').get('simd_type')
|
2021-09-26 12:54:14 +08:00
|
|
|
raise Exception("No query node found")
|
2021-09-17 13:19:49 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def query_nodes(self):
|
2021-09-24 14:14:10 +08:00
|
|
|
"""get all query nodes in Milvus deployment"""
|
2021-09-23 13:41:54 +08:00
|
|
|
query_nodes = []
|
|
|
|
for node in self.nodes:
|
2022-04-07 10:37:31 +08:00
|
|
|
if 'querynode' == node.get('infos').get('type'):
|
2021-09-23 13:41:54 +08:00
|
|
|
query_nodes.append(node)
|
|
|
|
return query_nodes
|
2021-09-17 13:19:49 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def data_nodes(self):
|
2021-09-24 14:14:10 +08:00
|
|
|
"""get all data nodes in Milvus deployment"""
|
2021-09-23 13:41:54 +08:00
|
|
|
data_nodes = []
|
|
|
|
for node in self.nodes:
|
2022-04-07 10:37:31 +08:00
|
|
|
if 'datanode' == node.get('infos').get('type'):
|
2021-09-23 13:41:54 +08:00
|
|
|
data_nodes.append(node)
|
|
|
|
return data_nodes
|
2021-09-17 13:19:49 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def index_nodes(self):
|
2021-09-24 14:14:10 +08:00
|
|
|
"""get all index nodes in Milvus deployment"""
|
2021-09-23 13:41:54 +08:00
|
|
|
index_nodes = []
|
|
|
|
for node in self.nodes:
|
2022-04-07 10:37:31 +08:00
|
|
|
if 'indexnode' == node.get('infos').get('type'):
|
2021-09-23 13:41:54 +08:00
|
|
|
index_nodes.append(node)
|
|
|
|
return index_nodes
|
2021-09-17 13:19:49 +08:00
|
|
|
|
2021-10-21 19:08:45 +08:00
|
|
|
@property
|
|
|
|
def proxy_nodes(self):
|
|
|
|
"""get all proxy nodes in Milvus deployment"""
|
|
|
|
proxy_nodes = []
|
|
|
|
for node in self.nodes:
|
2022-04-07 10:37:31 +08:00
|
|
|
if 'proxy' == node.get('infos').get('type'):
|
2021-10-21 19:08:45 +08:00
|
|
|
proxy_nodes.append(node)
|
|
|
|
return proxy_nodes
|
|
|
|
|
2021-09-18 10:41:50 +08:00
|
|
|
@property
|
|
|
|
def nodes(self):
|
2021-09-27 18:56:28 +08:00
|
|
|
"""get all the nodes in Milvus deployment"""
|
2024-05-31 13:55:52 +08:00
|
|
|
self.refresh()
|
2022-05-18 17:56:02 +08:00
|
|
|
all_nodes = json.loads(self.sys_info.response).get('nodes_info')
|
|
|
|
online_nodes = [node for node in all_nodes if node["infos"]["has_error"] is False]
|
|
|
|
return online_nodes
|
2021-09-28 10:38:03 +08:00
|
|
|
|
|
|
|
def get_nodes_by_type(self, node_type=None):
|
2021-09-30 18:05:39 +08:00
|
|
|
"""get milvus nodes by node type"""
|
2021-09-29 19:46:06 +08:00
|
|
|
target_nodes = []
|
|
|
|
if node_type is not None:
|
|
|
|
for node in self.nodes:
|
|
|
|
if str(node_type).lower() == str(node.get('infos').get('type')).lower():
|
|
|
|
target_nodes.append(node)
|
|
|
|
return target_nodes
|
2022-05-18 17:56:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
connections.connect(host="10.96.250.111", port="19530")
|
|
|
|
ms = MilvusSys()
|