get_hot_threads
Identify high-CPU threads on OpenSearch nodes to diagnose performance bottlenecks and optimize cluster resource usage.
Instructions
Check hot threads on nodes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The main handler function for the 'get_hot_threads' tool. It queries the OpenSearch '/_nodes/hot_threads' endpoint, filters lines containing CPU usage percentages ('%'), and returns the results as TextContent. Handles errors gracefully.async def get_hot_threads() -> list[TextContent]: """ Get hot threads information from all nodes, filtering for CPU percentage data. Returns only thread information containing percentage signs, indicating CPU usage. If no threads show percentage usage, indicates no hot threads were found. """ self.logger.info("Fetching hot threads information...") try: response = self.es_client.transport.perform_request( 'GET', '/_nodes/hot_threads' ) # Filter lines containing '%' hot_lines = [line for line in str(response).split('\n') if '%' in line] if hot_lines: return [TextContent(type="text", text='\n'.join(hot_lines))] else: return [TextContent(type="text", text="No hot threads detected in the cluster.")] except Exception as e: self.logger.error(f"Error fetching hot threads: {e}") return [TextContent(type="text", text=f"Error: {str(e)}")]
- The @mcp.tool decorator registers the get_hot_threads handler function with the MCP server, providing a description for the tool.@mcp.tool(description="Check hot threads on nodes")
- src/opensearch_mcp_server/server.py:41-41 (registration)Invocation of register_tools on the AdminClusterTools instance, which triggers the registration of get_hot_threads and other admin cluster tools.admin_cluster_tools.register_tools(self.mcp)