1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| package main;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.Mem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
public class Main {
//-------------------------------------------------------
//Loading Required Libraries
//-------------------------------------------------------
public static void loadDLL() throws IOException {
//Creating temp file
File tempFile = File.createTempFile("sigar-amd64-winnt", ".dll");
try (InputStream input = Main.class.getResourceAsStream("sigar-amd64-winnt.dll");
OutputStream output = new FileOutputStream(tempFile)) {
byte[] buf = new byte[8192];
int len;
while ( (len=input.read(buf)) > 0 ) {
output.write(buf, 0, len);
}
output.flush();
}
System.setProperty("java.library.path",tempFile.getParent());
System.out.println("Librairie extraite");
tempFile.deleteOnExit();
//Loading Library
//System.load(tempFile.getAbsolutePath());
//-------------------------------------------------------
}
private static Sigar sigar = new Sigar();
//-----------------------------------------------------------
//Getting General Informations Method
//-----------------------------------------------------------
public static void getGeneralInformations() {
InetAddress ip;
try {
ip = InetAddress.getLocalHost();
System.out.println("Nom du PC : " + ip.getHostName());
System.out.println("Votre adresse IP locale: " + ip.getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
String os = System.getProperty("os.name");
String version = System.getProperty("os.version");
System.out.println("Système d'exploitation: " + os + " Version " + version);
}
//-----------------------------------------------------------
//-----------------------------------------------------------
//Getting Memory Informations Method
//-----------------------------------------------------------
public static void getInformationsAboutMemory() {
Mem mem = null;
try {
mem = sigar.getMem();
} catch (SigarException se) {
se.printStackTrace();
}
System.out.println("Mémoire RAM hors système: " + mem.getTotal() / 1024 / 1024 + " MB soit " + mem.getTotal() / 1024 / 1024 / 1024 + " GB");
}
//-----------------------------------------------------------
//-----------------------------------------------------------
//Getting CPU Informations Method
//-----------------------------------------------------------
static CpuInfo[] infos = null;
public static void getInformationsAboutCPU() {
try {
infos = sigar.getCpuInfoList();
} catch (SigarException se) {
se.printStackTrace(); }
org.hyperic.sigar.CpuInfo info = infos[0];
System.out.println("Processeur: " + info.getVendor() + " " + info.getModel() + " || " + info.getTotalCores() + " coeurs");
}
//-----------------------------------------------------------
//-----------------------------------------------------------
//Getting GPU Informations Method
//-----------------------------------------------------------
public static void getInformationsAboutGPU() {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
int height = d.height;
int width = d.width;
System.out.println("Résolution de l'écran: " + width + "X" + height);
}
//-----------------------------------------------------------
public static void main(String args[]) throws IOException {
//----------Calling for DLL importation method-----------
loadDLL();
//-------------------------------------------------------
//----------------Displaying Informations----------------
getGeneralInformations();
getInformationsAboutCPU();
getInformationsAboutMemory();
getInformationsAboutGPU();
//-------------------------------------------------------
//--------------Displaying Usage Frames------------------
try {
CPUUsageFrame cpuFrame = new CPUUsageFrame(); // Displaying CPU usage frame
new MEMUsageFrame(cpuFrame); //Displaying RAM usage frame
} catch (SigarException e) {
e.printStackTrace();
}
//-------------------------------------------------------
}
} |