GetCpuUsageData
Retrieve CPU usage data for Alibaba Cloud ECS instances to monitor performance and optimize resource allocation. Specify region and instance IDs for accurate, actionable insights.
Instructions
获取ECS实例的CPU使用率数据
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| InstanceIds | Yes | AlibabaCloud ECS instance ID List | |
| RegionId | No | AlibabaCloud region ID | cn-hangzhou |
Implementation Reference
- The main handler function for the CMS_GetCpuUsageData tool, which retrieves CPU usage data ('cpu_total' metric) for specified ECS instance IDs in a given Alibaba Cloud region using the CMS API.
def CMS_GetCpuUsageData( InstanceIds: List[str] = Field(description='AlibabaCloud ECS instance ID List'), RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou') ): """获取ECS实例的CPU使用率数据""" return _get_cms_metric_data(RegionId, InstanceIds, 'cpu_total') - Supporting helper function that fetches the last metric data points from Alibaba Cloud CMS for given instance IDs and metric name, used by CPU usage and other metric tools.
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) logger.info(f'CMS Tools response: {describe_metric_last_resp.body}') return describe_metric_last_resp.body.datapoints - src/alibaba_cloud_ops_mcp_server/server.py:84-85 (registration)Code that registers all tools from cms_tools (including CMS_GetCpuUsageData) with the FastMCP server instance.
for tool in cms_tools.tools: mcp.tool(tool) - Helper function to create a CMS client configured for the specified region endpoint.
def create_client(region_id: str) -> cms20190101Client: config = create_config() config.endpoint = f'metrics.{region_id}.aliyuncs.com' return cms20190101Client(config) - src/alibaba_cloud_ops_mcp_server/server.py:7-7 (registration)Import statement that brings in the cms_tools module containing the tool definitions and tools list.
from alibaba_cloud_ops_mcp_server.tools import cms_tools, oos_tools, oss_tools, api_tools, common_api_tools