All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aol.micro.server.machine.stats.sigar.SigarStats Maven / Gradle / Ivy

The newest version!
package com.aol.micro.server.machine.stats.sigar;

import java.util.Map;

import cyclops.companion.MapXs;
import org.hyperic.sigar.Sigar;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.aol.micro.server.StatsSupplier;

@Component
public class SigarStats implements StatsSupplier {
    private final MachineStatsChecker checker;
    private final long statsDelay;
    private final boolean cpuOnly;
    private volatile long lastRan = 0;
    private volatile boolean lastRanValue = true;

    public SigarStats(MachineStatsChecker checker, @Value("${stats.checker.delay:1000}") long statsDelay,
            @Value("${stats.checker.cpu.only:true}") boolean cpuOnly) {
        this.statsDelay = statsDelay;
        this.checker = checker;
        this.cpuOnly = cpuOnly;
    }

    @Override
    public Map> get() {
        if (cpuOnly)
            return MapXs.of("cpu-stats", checker.cpuStats(new Sigar())
                                                .toMap());
        MachineStats stats = checker.getStats(new Sigar());
        return stats.toMap();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy