获取服务器信息 java版本

代码来源于 <<代码生产工具mapleLeaf>>

GitHub地址:https://github.com/q200737056/mapleLeaf

 

先上一张效果图

结果响应

 

实现代码

	@RequestMapping("/index")
	@ResponseBody
	public AjaxResult<Map<String,String>> index(HttpServletRequest request){
		Properties props = System.getProperties();
        //java版本
        String javaVersion = props.getProperty("java.version");
        //操作系统名称
        String osName = props.getProperty("os.name") + props.getProperty("os.version");
        //用户的主目录
        String userHome = props.getProperty("user.home");
        //用户的当前工作目录
        String userDir = props.getProperty("user.dir");
        //服务器IP
        String serverIP = request.getLocalAddr();
        //客户端IP
        String clientIP = request.getRemoteHost();
        //WEB服务器
        String webVersion = request.getServletContext().getServerInfo();
        //CPU个数
        String cpu = Runtime.getRuntime().availableProcessors() + "核";
        //虚拟机内存总量
        String totalMemory = (Runtime.getRuntime().totalMemory() / 1024 / 1024) + "M";
        //虚拟机空闲内存量
        String freeMemory = (Runtime.getRuntime().freeMemory() / 1024 / 1024) + "M";
        //虚拟机使用的最大内存量
        String maxMemory = (Runtime.getRuntime().maxMemory() / 1024 / 1024) + "M";
       
        //网站根目录
        String webRootPath = request.getSession().getServletContext().getRealPath("");
        Map<String, String> propsMap = new HashMap<>();
        propsMap.put("javaVersion", javaVersion);
        propsMap.put("osName", osName);
        propsMap.put("userHome", userHome);
        propsMap.put("userDir", userDir);
        propsMap.put("clientIP", clientIP);
        propsMap.put("serverIP", serverIP);
        propsMap.put("cpu", cpu);
        propsMap.put("totalMemory", totalMemory);
        propsMap.put("freeMemory", freeMemory);
        propsMap.put("maxMemory", maxMemory);
        propsMap.put("webVersion", webVersion);
        propsMap.put("webRootPath", webRootPath);
        
        AjaxResult<Map<String,String>> result = new AjaxResult<Map<String,String>>();
        result.setCode("0");
        result.setData(propsMap);
        
        return result;
	}

 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值