com.alachisoft.ncache.common.caching.statistics.customcounters.systemcounters.SystemCounter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.alachisoft.ncache.common.caching.statistics.customcounters.systemcounters;
import Alachisoft.NCache.Common.Common;
import Alachisoft.NCache.Common.Enum.EventType;
import Alachisoft.NCache.Common.Logger.EventLogger;
import com.alachisoft.ncache.common.caching.statistics.customcounters.InstantaneousCounter;
import org.hyperic.sigar.Sigar;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.OperatingSystemMXBean;
/**
* @author Muneeb Shahid
*/
public abstract class SystemCounter extends InstantaneousCounter {
public static java.util.List m;
private static Sigar sigar = null;
private static java.lang.management.OperatingSystemMXBean oSMXBean;
private static java.lang.management.MemoryMXBean memoryMXBean;
private static java.lang.management.MemoryUsage memoryUsage;
static {
try {
sigar = new Sigar();
} catch (Throwable e) {
//System.err.println(e.getMessage());
//System.err.println("System counters will not be published on snmp.");
EventLogger.LogEvent("System counters will not be published on JMX or snmp.", EventType.ERROR);
}
try {
oSMXBean = ManagementFactory.getOperatingSystemMXBean();
memoryMXBean = ManagementFactory.getMemoryMXBean();
m = ManagementFactory.getMemoryPoolMXBeans();
} catch (Throwable e) {
//System.err.println(e.getMessage());
//System.err.println("System counters will not be published on JMX.");
EventLogger.LogEvent("System counters will not be published on JMX.", EventType.ERROR);
}
}
public SystemCounter(String name, String instance) {
super(name, instance);
}
public static Sigar getSigar() {
return sigar;
}
public static OperatingSystemMXBean getJavaOSMXBean() {
return oSMXBean;
}
public static com.sun.management.OperatingSystemMXBean getSunOSMXBean() {
try {
if (oSMXBean != null) {
return (com.sun.management.OperatingSystemMXBean) oSMXBean;
}
} catch (Throwable e) {
e.getMessage();
}
return null;
}
public static MemoryMXBean getMemoryMXBean() {
return memoryMXBean;
}
@Override
protected abstract void calculate(double value);
@Override
protected void flipChanged() {
calculate(_value);
}
@Override
public void decrement() {
}
@Override
public void decrementBy(double value) {
}
@Override
public double getValue() {
updateIfFlipChanged();
return _value;
}
@Override
public void setValue(double _value) {
super._value = Common.roundOff(_value, 1);
}
public double toMegaBytes(double bytes) {
return bytes / 1048576; // 1048576 = (1024 (KB) * 1024) MB
}
}