Skip to content

Java Lightweight Hardware Monitoring Tool

License

Notifications You must be signed in to change notification settings

stacks-cubic/sc-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stacks Cubic Monitor

MIT License Java CodeQL Bugs Vulnerabilities

Quality Gate Status Maintainability Rating Reliability Rating Security Rating

Java lightweight hardware monitoring tool, with a size of only 12KB, provides CPU load, disk IO, memory occupation and network traffic monitoring; The monitoring data will be output in the terminal and log file (optional).

Install

Not yet released

Use

Async

Full example

public class example implements UseCallback {
    public void text() {
        try {
            // Create collection work
            // Param1 is use callback
            // Param2 is collection interval time (seconds)
            Work work = new Work(this, 60);
            // Set the location to save the log, it will not be saved if not set
            work.save("./")
                    // No collection CPU data
                    .excludeCPU()
                    // No collection Disk data
                    .excludeDisk()
                    // No collection Memory data
                    .excludeMemory()
                    // No collection Network data
                    .excludeNetwork()
                    // Start work
                    .run();
        } catch (NoCollectorException e) {
            // Minimum 1 collection item needs to be enabled!
        }
    }

    @Override
    public void receive(UsePacker packer) {
        CpuUse cpu = packer.getCpu();
        DiskUse disk = packer.getDisk();
        MemoryUse memory = packer.getMemory();
        NetworkUse network = packer.getNetwork();
    }
}

Output to terminal

public class example {
    public void text() {
        try {
            Work work = new Work();
            work.run();
        } catch (NoCollectorException e) {
            // Minimum 1 collection item needs to be enabled!
        }
    }
}

Output to file

public class example {
    public void text() {
        try {
            Work work = new Work();
            // Param is file save location
            work.save("./").run();
        } catch (NoCollectorException e) {
            // Minimum 1 collection item needs to be enabled!
        }
    }
}

Output to callback

public class example implements UseCallback {
    public void text() {
        try {
            Work work = new Work(this);
            work.run();
        } catch (NoCollectorException e) {
            // Minimum 1 collection item needs to be enabled!
        }
    }

    @Override
    public void receive(UsePacker packer) {
        CpuUse cpu = packer.getCpu();
        DiskUse disk = packer.getDisk();
        MemoryUse memory = packer.getMemory();
        NetworkUse network = packer.getNetwork();
    }
}

Sync

public class example {
    public void text() {
        // no callback, no save, collect all data
        Obtain obtain = new Obtain();
        UsePacker packer = obtain.syncCollectionData();
        // custom collection items
        obtain = new Obtain(false, false, true, true);
        packer = obtain.syncCollectionData();
        // customizing collection items and save locations
        obtain = new Obtain(".", true, true, false, false);
        packer = obtain.syncCollectionData();
    }
}

Exception

NoCollectorException

The Work provides 4 exclusion methods, you will get this exception if you exclude all collection items

How to build

sc-monitor uses Maven as its build tool.

Since we rely on oshi-core requires Java 8 or later.

Acknowledgements

License

This project is licensed under the MIT License.

Releases

No releases published

Packages

No packages published

Languages