Skip to main content
Glama

get_metric_statistics

Retrieve CloudWatch metric statistics to monitor AWS resource performance by specifying namespace, metric name, time range, and statistical measures.

Instructions

Retrieves statistics for a specific CloudWatch metric.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceYesThe namespace of the metric (e.g., AWS/EC2).
metric_nameYesThe name of the metric (e.g., CPUUtilization).
dimensionsNoArray of dimensions (e.g., [{Name: 'InstanceId', Value: 'i-xxx'}]).
start_timeNoStart time (ISO string).
end_timeNoEnd time (ISO string).
periodNoGranularity in seconds (default: 300).
statisticsNoStatistics to retrieve (e.g., ['Average', 'Maximum']).

Implementation Reference

  • The main handler function for the 'get_metric_statistics' tool. It constructs and sends a GetMetricStatisticsCommand to the CloudWatch client using the provided namespace, metric name, dimensions, time range, period, and statistics. Applies defaults where necessary and formats the datapoints response.
    if (name === "get_metric_statistics") {
        const { namespace, metric_name, dimensions, start_time, end_time, period, statistics } = (args as any);
    
        // Defualts
        const actualStartTime = start_time ? new Date(start_time) : new Date(Date.now() - 24 * 60 * 60 * 1000); // 24h ago
        const actualEndTime = end_time ? new Date(end_time) : new Date();
        const actualPeriod = period || 300; // 5 mins
        const actualStats = statistics || ["Average"];
    
        // Convert dimensions to right format: { Name, Value } is already expected from args.
    
        const command = new GetMetricStatisticsCommand({
            Namespace: namespace,
            MetricName: metric_name,
            Dimensions: dimensions,
            StartTime: actualStartTime,
            EndTime: actualEndTime,
            Period: actualPeriod,
            Statistics: actualStats
        });
        const response = await cloudWatchClient.send(command);
    
        const datapoints = response.Datapoints?.sort((a, b) => (a.Timestamp?.getTime() || 0) - (b.Timestamp?.getTime() || 0))
            .map(dp => ({
                Timestamp: dp.Timestamp,
                Average: dp.Average,
                Maximum: dp.Maximum,
                Minimum: dp.Minimum,
                Sum: dp.Sum,
                SampleCount: dp.SampleCount,
                Unit: dp.Unit
            })) || [];
    
        return { content: [{ type: "text", text: JSON.stringify(datapoints, null, 2) }] };
    }
  • src/index.ts:661-683 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining the tool name, description, and input schema (Zod-like structure).
    {
        name: "get_metric_statistics",
        description: "Retrieves statistics for a specific CloudWatch metric.",
        inputSchema: {
            type: "object",
            properties: {
                namespace: { type: "string", description: "The namespace of the metric (e.g., AWS/EC2)." },
                metric_name: { type: "string", description: "The name of the metric (e.g., CPUUtilization)." },
                dimensions: {
                    type: "array",
                    items: {
                        type: "object",
                        properties: { Name: { type: "string" }, Value: { type: "string" } }
                    },
                    description: "Array of dimensions (e.g., [{Name: 'InstanceId', Value: 'i-xxx'}])."
                },
                start_time: { type: "string", description: "Start time (ISO string)." },
                end_time: { type: "string", description: "End time (ISO string)." },
                period: { type: "number", description: "Granularity in seconds (default: 300)." },
                statistics: { type: "array", items: { type: "string" }, description: "Statistics to retrieve (e.g., ['Average', 'Maximum'])." }
            },
            required: ["namespace", "metric_name"]
        }
  • Input schema definition for the get_metric_statistics tool, specifying parameters like namespace, metric_name (required), dimensions, time range, period, and statistics.
    inputSchema: {
        type: "object",
        properties: {
            namespace: { type: "string", description: "The namespace of the metric (e.g., AWS/EC2)." },
            metric_name: { type: "string", description: "The name of the metric (e.g., CPUUtilization)." },
            dimensions: {
                type: "array",
                items: {
                    type: "object",
                    properties: { Name: { type: "string" }, Value: { type: "string" } }
                },
                description: "Array of dimensions (e.g., [{Name: 'InstanceId', Value: 'i-xxx'}])."
            },
            start_time: { type: "string", description: "Start time (ISO string)." },
            end_time: { type: "string", description: "End time (ISO string)." },
            period: { type: "number", description: "Granularity in seconds (default: 300)." },
            statistics: { type: "array", items: { type: "string" }, description: "Statistics to retrieve (e.g., ['Average', 'Maximum'])." }
        },
        required: ["namespace", "metric_name"]
  • Import of the AWS SDK GetMetricStatisticsCommand used by the tool handler.
    import { GetMetricStatisticsCommand } from "@aws-sdk/client-cloudwatch";
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states 'Retrieves' which implies a read operation, but doesn't disclose behavioral traits like authentication requirements, rate limits, pagination, error conditions, or what 'statistics' specifically includes (e.g., percentiles, counts). This leaves significant gaps for a tool with 7 parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized and front-loaded, with every word earning its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 7 parameters, no annotations, and no output schema, the description is minimally adequate but lacks completeness. It doesn't explain return values, error handling, or behavioral constraints, which are important for a statistics retrieval tool. However, the clear purpose and concise structure provide a basic foundation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 7 parameters. The description adds no parameter-specific information beyond what's in the schema, but doesn't need to compensate for gaps. Baseline 3 is appropriate when the schema does all the work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Retrieves') and resource ('statistics for a specific CloudWatch metric'), making the purpose unambiguous. However, it doesn't differentiate from sibling tools like 'list_cloudwatch_alarms' or 'search_cloudwatch_logs', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With many sibling tools in the AWS/CloudWatch space, there's no mention of prerequisites, typical use cases, or comparisons to tools like 'list_cloudwatch_alarms', leaving the agent with insufficient context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bhaveshopss/MCP-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server