get_memory_usage_data
Retrieve memory usage data for Alibaba Cloud ECS instances to monitor performance and identify resource constraints.
Instructions
获取ECS实例内存使用率数据
Args:
region: 区域ID,如cn-beijing
instance_ids: ECS实例ID列表
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | cn-beijing | |
| instance_ids | No |
Implementation Reference
- complete_fastmcp_server.py:255-277 (handler)The primary handler for the 'get_memory_usage_data' tool, registered via @app.tool(). It dynamically locates and invokes the CMS_GetMemUsageData helper from cms_tools to fetch memory usage metrics from Alibaba Cloud CloudMonitor.@app.tool() def get_memory_usage_data(region: str = "cn-beijing", instance_ids: List[str] = None) -> str: """获取ECS实例内存使用率数据 Args: region: 区域ID,如cn-beijing instance_ids: ECS实例ID列表 """ try: sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'alibaba_cloud_ops_mcp_server')) from tools import cms_tools if not instance_ids: instance_ids = ["示例实例ID"] for tool_func in cms_tools.tools: if hasattr(tool_func, '__name__') and 'mem' in tool_func.__name__.lower() and 'usage' in tool_func.__name__.lower(): result = tool_func(RegionId=region, InstanceIds=instance_ids) return str(result) return f"内存使用率监控功能可用,region: {region}, 实例: {instance_ids}" except Exception as e: return f"内存监控查询失败: {str(e)}"
- Helper function specifically providing memory usage (utilization) data via CloudMonitor API. Dynamically selected and called by the main handler based on name matching.@tools.append def CMS_GetMemUsageData( InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'), RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou') ): """获取内存利用率指标数据""" return _get_cms_metric_data(RegionId, InstanceIds, 'memory_usedutilization')
- Core helper utility that executes the actual Alibaba Cloud CMS DescribeMetricLast API call to retrieve metric datapoints for the specified metric (e.g., memory_usedutilization).def _get_cms_metric_data(region_id: str, instance_ids: List[str], metric_name: str): client = create_client(region_id) dimesion = [] for instance_id in instance_ids: dimesion.append({ 'instanceId': instance_id }) describe_metric_last_request = cms_20190101_models.DescribeMetricLastRequest( namespace='acs_ecs_dashboard', metric_name=metric_name, dimensions=json.dumps(dimesion), ) describe_metric_last_resp = client.describe_metric_last(describe_metric_last_request) return describe_metric_last_resp.body.datapoints
- complete_fastmcp_server.py:255-255 (registration)The @app.tool() decorator registers the get_memory_usage_data function as an MCP tool in the FastMCP server.@app.tool()
- Pydantic Field definitions providing input schema/validation for the underlying CMS_GetMemUsageData helper (region and instance_ids parameters).InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'), RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou') ):