Search in sources :

Example 1 with CachedGauge

use of com.codahale.metrics.CachedGauge in project alluxio by Alluxio.

the class OperationSystemGaugeSet method getMetrics.

@Override
public Map<String, Metric> getMetrics() {
    final Map<String, Metric> gauges = new HashMap<>();
    try {
        mOsmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        mUnixb = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    } catch (Throwable e) {
        return gauges;
    }
    gauges.put("os.freePhysicalMemory", new CachedGauge(10, TimeUnit.MINUTES) {

        @Override
        protected Long loadValue() {
            return mOsmxb.getFreePhysicalMemorySize();
        }
    });
    gauges.put("os.totalPhysicalMemory", new CachedGauge<Long>(10, TimeUnit.MINUTES) {

        @Override
        protected Long loadValue() {
            return mOsmxb.getTotalPhysicalMemorySize();
        }
    });
    gauges.put("os.cpuLoad", new CachedGauge<Double>(10, TimeUnit.MINUTES) {

        @Override
        protected Double loadValue() {
            return mOsmxb.getSystemCpuLoad();
        }
    });
    gauges.put("os.maxFileCount", new CachedGauge<Long>(10, TimeUnit.MINUTES) {

        @Override
        protected Long loadValue() {
            return mUnixb.getMaxFileDescriptorCount();
        }
    });
    gauges.put("os.openFileCount", new CachedGauge<Long>(10, TimeUnit.MINUTES) {

        @Override
        protected Long loadValue() {
            return mUnixb.getOpenFileDescriptorCount();
        }
    });
    return gauges;
}
Also used : HashMap(java.util.HashMap) CachedGauge(com.codahale.metrics.CachedGauge) Metric(com.codahale.metrics.Metric)

Aggregations

CachedGauge (com.codahale.metrics.CachedGauge)1 Metric (com.codahale.metrics.Metric)1 HashMap (java.util.HashMap)1