Package com.sun.management

Examples of com.sun.management.OperatingSystemMXBean


    // 剩余内存
    long freeMemory = Runtime.getRuntime().freeMemory() / kb;
    // 最大可使用内存
    long maxMemory = Runtime.getRuntime().maxMemory() / kb;

    OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
        .getOperatingSystemMXBean();

    // 操作系统
    String osName = System.getProperty("os.name");
    // 总的物理内存
    long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / kb;
    // 剩余的物理内存
    long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / kb;
    // 已使用的物理内存
    long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb
        .getFreePhysicalMemorySize()) / kb;

    // 获得线程总数
    ThreadGroup parentThread;
    for (parentThread = Thread.currentThread().getThreadGroup(); parentThread
View Full Code Here


     * @since 1.15.0.4
     */
    public static long getSuggestedMaxJvmHeapSize() {
        try {
            Object bean = ManagementFactory.getOperatingSystemMXBean();
            OperatingSystemMXBean osMxBean = (OperatingSystemMXBean) bean;
            long systemMemoryBytes = osMxBean.getTotalPhysicalMemorySize();
            long systemMemoryMegabytes = systemMemoryBytes >> 20;
            long halfOfMemory = systemMemoryMegabytes / 2;
            long result = halfOfMemory;

            // Systems today may have a lot of memory - 4 or 6GB - and half
View Full Code Here

public class HealthStatisticsReader {
    private static final int MB = 1024 * 1024;
    private static final Log log = LogFactory.getLog(HealthStatisticsReader.class);

    public static double getMemoryConsumption() {
      OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        double totalMemory = (double)(osBean.getTotalPhysicalMemorySize()/ MB);
        double usedMemory = (double)((totalMemory - (osBean.getFreePhysicalMemorySize() / MB) ));
       
        if(log.isDebugEnabled()) {
          log.debug("Calculating memory consumption: [totalMemory] "+totalMemory+" [usedMemory] "+usedMemory);
        }
        double memoryConsumption = (usedMemory / totalMemory) * 100;
 
View Full Code Here

    public void execute(MicroContext context, Map configuration) throws ControllerException {
        Map<String, Object> systemInfo = new HashMap<String, Object>();
        Map<String, Object> osMap = new HashMap<String, Object>();
        MBeanServerConnection mbeanServer = ManagementFactory.getPlatformMBeanServer();

        OperatingSystemMXBean sunOperatingSystemMXBean = null;
        try {
            sunOperatingSystemMXBean = ManagementFactory.newPlatformMXBeanProxy(
                    mbeanServer, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
        } catch (IOException e) {
            throw new ControllerException(e.getMessage());
        }

        Runtime rt = Runtime.getRuntime();
        long totalMemory = rt.totalMemory() / MEGA_BYTE;
        long freeMemory = rt.freeMemory() / MEGA_BYTE;
        long usedMemory = totalMemory - freeMemory;

        final long p100 = (int) Math.round(((double) freeMemory / (double) totalMemory) * 100);

        Map<String, Long> memInfo = new HashMap<String, Long>();

        memInfo.put("total", totalMemory);
        memInfo.put("used", usedMemory);
        memInfo.put("free", freeMemory);
        memInfo.put("percent_free", p100);

        systemInfo.put("memory", memInfo);
        systemInfo.put("powered_by", POWERED_BY_MICRO);

        //cpu usage in milli secs
        long currentCpuUsage = sunOperatingSystemMXBean.getProcessCpuTime() / 1000000;
        osMap.put("cpu_usage", currentCpuUsage);
        osMap.put("available_processors", sunOperatingSystemMXBean.getAvailableProcessors());
        osMap.put("system_load_average", sunOperatingSystemMXBean.getSystemLoadAverage());
        osMap.put("committed_virtual_memory_size", sunOperatingSystemMXBean.getCommittedVirtualMemorySize());
        osMap.put("free_physical_memory_size", sunOperatingSystemMXBean.getFreePhysicalMemorySize());
        osMap.put("total_physical_memory_size", sunOperatingSystemMXBean.getTotalPhysicalMemorySize());
        osMap.put("free_swap_space_size", sunOperatingSystemMXBean.getFreeSwapSpaceSize());
        osMap.put("total_swap_space_size", sunOperatingSystemMXBean.getTotalSwapSpaceSize());


        systemInfo.put("os", osMap);

        List<GarbageCollectorMXBean> gc = ManagementFactory.getGarbageCollectorMXBeans();
View Full Code Here

        long currentXmx = getMb(Runtime.getRuntime().maxMemory());
        return currentXmx < maxXmx;
    }

    private long getMaximumXmx() {
        OperatingSystemMXBean mxbean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        long totalMemory = mxbean.getTotalPhysicalMemorySize();
        String arch = System.getProperty("sun.arch.data.model");
        if (getMb(totalMemory) < 2100 || arch.equals("32")) {
            return getBytes(1300);
        } else {
            return (long) (totalMemory * 0.7);
 
View Full Code Here

    // 剩余内存
    long freeMemory = Runtime.getRuntime().freeMemory() / kb;
    // 最大可使用内存
    long maxMemory = Runtime.getRuntime().maxMemory() / kb;

    OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
        .getOperatingSystemMXBean();

    // 操作系统
    String osName = System.getProperty("os.name");
    // 总的物理内存
    long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / kb;
    // 剩余的物理内存
    long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / kb;
    // 已使用的物理内存
    long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb
        .getFreePhysicalMemorySize()) / kb;

    // 获得线程总数
    ThreadGroup parentThread;
    for (parentThread = Thread.currentThread().getThreadGroup(); parentThread
View Full Code Here

    protected long getMemoryUsed() {
        return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024);
    }

    protected double getCpu() {
        OperatingSystemMXBean osbean = (OperatingSystemMXBean) ManagementFactory
                .getOperatingSystemMXBean();
        RuntimeMXBean runbean = java.lang.management.ManagementFactory
                .getRuntimeMXBean();
        long uptime = runbean.getUptime();
        long processCpuTime = osbean.getProcessCpuTime();
        //cpu count
        int processors = osbean.getAvailableProcessors();
        //uptime in milliseconds ,and    processCpuTime in nao seconds
        double cpu = (processCpuTime - lastProcessCpuTime) / ((uptime - lastUptime) * 10000f * processors);
        lastProcessCpuTime = processCpuTime;
        lastUptime = uptime;
        return (int) cpu;  //
View Full Code Here

TOP

Related Classes of com.sun.management.OperatingSystemMXBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.