Arthas JVM监控控制台
一个基于 Arthas 的 JVM 监控和控制平台服务器,提供 Python 接口,用于监控和分析 Java 进程,具备线程分析、内存监控和性能诊断等功能。
服务介绍
JVM MCP Server
基于Arthas的JVM监控MCP服务器实现,提供简单易用的Python接口来监控和分析Java进程。
功能
- 自动下载和管理Arthas工具
- 支持本地和远程Java进程监控
- 查询Java进程列表
- 实时JVM线程信息
- 监控JVM内存使用情况
- 线程堆栈跟踪信息
- 查询类加载信息
- 支持类和方法反编译
- 方法调用监控
- 动态调整日志级别
- 基于AI的JVM性能分析
系统要求
- Python 3.10+
- Java运行环境 (JRE) 8+
- 网络连接(用于下载Arthas)
- 目标服务器的SSH访问权限(如果使用远程模式)
安装与环境设置
1. 安装uv工具
## linux shell
curl -LsSf https://astral.sh/uv/install.sh | sh
## or install using pip
pip install uv
## or install using pipx (if you have pipx installed)
pipx install uv
## windows powershell
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
2. 克隆项目
git clone https://github.com/xzq-xu/jvm-mcp-server.git
cd jvm-mcp-server
3. 使用uv初始化项目环境
# Create virtual environment
uv venv
# Sync project dependencies
uv sync
4. 配置环境变量(可选,用于远程连接)
创建一个.env文件并添加以下配置:
# Linux/Mac
ARTHAS_SSH_HOST=user@remote-host
ARTHAS_SSH_PORT=22 # Optional, default is 22
ARTHAS_SSH_PASSWORD=your-password # If using password authentication
# Windows PowerShell
$env:ARTHAS_SSH_HOST="user@remote-host"
$env:ARTHAS_SSH_PORT="22" # Optional, default is 22
$env:ARTHAS_SSH_PASSWORD="your-password" # If using password authentication
快速开始
- 使用uv启动服务器:
# Start in local mode
uv run jvm-mcp-server
# Start with environment file (if remote connection is configured)
uv run --env-file .env jvm-mcp-server
# Start in a specific directory (if needed)
uv --directory /path/to/project run --env-file .env jvm-mcp-server
- 在Python代码中使用:
from jvm_mcp_server import JvmMcpServer
server = JvmMcpServer()
server.run()
- 使用MCP工具:
使用配置文件:
{
"mcpServers": {
"jvm-mcp-server": {
"command": "uv",
"args": [
"--directory",
"/path/to/jvm-mcp-server",
"run",
"--env-file",
"/path/to/jvm-mcp-server/.env",
"jvm-mcp-server"
]
}
}
}
不使用配置文件时,将读取系统环境变量,如果没有则会监控本地线程:
{
"mcpServers": {
"jvm-mcp-server": {
"command": "uv",
"args": [
"--directory",
"/path/to/jvm-mcp-server",
"run",
"jvm-mcp-server"
]
}
}
}
可用工具
重要提示
- 确保运行环境中已安装Java
- Arthas工具将在首次运行时自动下载(arthas会被下载到用户主目录下,可以提前下载并命名为arthas-boot.jar)
- 需要对目标Java进程有访问权限
- 远程模式需要SSH访问权限及适当的用户权限
- 建议在开发环境中使用,在生产环境中使用前应仔细评估
反馈
如果您遇到任何问题,请提交Issue或Pull Request。