| | |
| | | package com.whyc.util; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.*; |
| | | import java.util.Locale; |
| | | import java.util.Scanner; |
| | | |
| | | /** |
| | |
| | | |
| | | public static String getCPUNumber(){ |
| | | String os = System.getProperty("os.name").toLowerCase(); |
| | | System.out.println(os); |
| | | //System.out.println(os); |
| | | Process process = null; |
| | | String serial = null; |
| | | if(os.contains("window")) { |
| | | System.out.println("windows"); |
| | | //System.out.println("windows"); |
| | | try { |
| | | process = Runtime.getRuntime().exec( |
| | | new String[]{"wmic", "cpu", "get", "ProcessorId"}); |
| | |
| | | } |
| | | }else{ |
| | | //linux |
| | | System.out.println("linux"); |
| | | //System.out.println("linux"); |
| | | serial =getSerialNumber("dmidecode -t processor | grep 'ID'", "ID",":"); |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 集成在主板Bios上的操作系统UUID |
| | | * @return |
| | | */ |
| | | public static String getBoisNumber(){ |
| | | String os = System.getProperty("os.name").toLowerCase(); |
| | | Process process = null; |
| | |
| | | } |
| | | }else { |
| | | //linux |
| | | serial =getSerialNumber("dmidecode |grep 'Serial Number'", "Serial Number",":"); } |
| | | serial =getSerialNumber("dmidecode |grep 'Serial Number'", "Serial Number",":"); |
| | | } |
| | | |
| | | return serial; |
| | | |
| | |
| | | } |
| | | }else { |
| | | //linux |
| | | serial=getSerialNumber("fdisk -l", "Disk identifier",":"); |
| | | //中英文环境下,fdisk命令不同的结果,一个是中文,一个是英文名 |
| | | Locale locale = Locale.getDefault(); |
| | | if((locale.getLanguage().equals("zh"))){ |
| | | serial=getSerialNumber("fdisk -l", "磁盘标识符",":"); |
| | | }else{ //不是中文,则采用en_US |
| | | serial=getSerialNumber("fdisk -l", "Disk identifier",":"); |
| | | } |
| | | } |
| | | return serial; |
| | | } |
| | | |
| | | /** |
| | | * 所有业务数据已占用的表空间大小的总和(单位:MB) |
| | | * /tg使用,服务器为linux,空间包含:应用大小:/app 和 数据库存储大小: /var/lib/mysql/ |
| | | * @return |
| | | */ |
| | | public static Integer getDataTableSpace(){ |
| | | int dataTableSpace=0; |
| | | String execResult = executeLinuxCmd("du -sh /app /var/lib/mysql"); |
| | | //String execResult = executeLinuxCmd("du -sh /battery_system /var/lib"); |
| | | String[] infos = execResult.split("\n"); |
| | | |
| | | for(String info : infos) { |
| | | info = info.trim(); |
| | | info = info.replaceAll(" ", ""); |
| | | //String[] result = info.split(File.separator); |
| | | String[] result = info.split("\t"); |
| | | String spaceStr = result[0]; |
| | | int space = Integer.parseInt(spaceStr.substring(0, spaceStr.length() - 1)); |
| | | if(spaceStr.endsWith("G")){ |
| | | dataTableSpace += space * 1024; |
| | | }else if(spaceStr.endsWith("M")){ |
| | | dataTableSpace += space; |
| | | } |
| | | |
| | | } |
| | | |
| | | return dataTableSpace; |
| | | |
| | | } |
| | | |
| | | /**linux*/ |
| | | public static String executeLinuxCmd(String cmd) { |
| | | try { |
| | | System.out.println("got cmd job : " + cmd); |
| | | //System.out.println("got cmd job : " + cmd); |
| | | Runtime run = Runtime.getRuntime(); |
| | | Process process; |
| | | process = run.exec(cmd); |