How to get hardware and system information?

Asked

Viewed 1,518 times

11

I found only the class Runtime, but it returns only values in numbers, such as total memory and processors. Is there any API that returns data from hardware (processor version, RAM, architecture, etc.) as in Ccleaner?

  • I think it can help you https://support.hyperic.com/display/SIGAR/Home. Example of using http://stackoverflow.com/q/12214114/3792998

1 answer

4

I use the FOLLOW basically does what you asked: Documentation

After downloading the SAGAR API.Jar and including it in the build path, an example of usage is given below:

import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

import org.hyperic.sigar.Mem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

public class MemExample {
    private static Sigar sigar = new Sigar();

    public static void getInformationsAboutMemory() {
        System.out.println("**************************************");
        System.out.println("*** Informations about the Memory: ***");
        System.out.println("**************************************\n");

        Mem mem = null;
        try {
            mem = sigar.getMem();
        } catch (SigarException se) {
            se.printStackTrace();
        }

        System.out.println("Actual total free system memory: " + mem.getActualFree() / 1024 / 1024 + " MB");
        System.out.println("Actual total used system memory: " + mem.getActualUsed() / 1024 / 1024 + " MB");
        System.out.println("Total free system memory ......: " + mem.getFree() / 1024 / 1024 + " MB");
        System.out.println("System Random Access Memory....: " + mem.getRam() + " MB");
        System.out.println("Total system memory............: " + mem.getTotal() / 1024 / 1024 + " MB");
        System.out.println("Total used system memory.......: " + mem.getUsed() / 1024 / 1024 + " MB");

        System.out.println("\n**************************************\n");

    }

    public static void main(String[] args) throws Exception {
        getInformationsAboutMemory();
    }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.