當前位置: 首頁>>代碼示例>>Java>>正文


Java Sigar類代碼示例

本文整理匯總了Java中org.hyperic.sigar.Sigar的典型用法代碼示例。如果您正苦於以下問題:Java Sigar類的具體用法?Java Sigar怎麽用?Java Sigar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Sigar類屬於org.hyperic.sigar包,在下文中一共展示了Sigar類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: output

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
@Override
public void output(String[] args) throws SigarException {
    org.hyperic.sigar.CpuInfo[] infos = this.sigar.getCpuInfoList();
    org.hyperic.sigar.CpuInfo info = infos[0];
    long cacheSize = info.getCacheSize();
    try {
        bos.write(("== MACHINE INFORMATION ==\n").getBytes());
        bos.write(("Vendor........." + info.getVendor() + "\n").getBytes());
        bos.write(("Model.........." + info.getModel() + "\n").getBytes());
        bos.write(("Mhz............" + info.getMhz() + "\n").getBytes());
        bos.write(("Total CPUs....." + info.getTotalCores() + "\n").getBytes());
        if ((info.getTotalCores() != info.getTotalSockets())
                || (info.getCoresPerSocket() > info.getTotalCores())) {
            bos.write(("Physical CPUs.." + info.getTotalSockets() + "\n").getBytes());
            bos.write(("Cores per CPU.." + info.getCoresPerSocket() + "\n").getBytes());
        }

        if (cacheSize != Sigar.FIELD_NOTIMPL) {
            bos.write(("Cache size....." + cacheSize + "\n").getBytes());
        }
    } catch(Exception ex) {
        System.out.println("[CF LOG] Error retrieving system stats");
    }
}
 
開發者ID:OneSourceConsult,項目名稱:JavaProfiling-tool,代碼行數:25,代碼來源:CpuInfo.java

示例2: printNetworkInfo

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
private void printNetworkInfo(CommandSender sender, SigarProxy sigar) throws SigarException {
    //net upload download
    NetInterfaceStat usedNetInterfaceStat = null;
    String[] netInterfaceList = sigar.getNetInterfaceList();
    for (String interfaceName : netInterfaceList) {
        NetInterfaceStat interfaceStat = sigar.getNetInterfaceStat(interfaceName);
        if (interfaceStat.getRxBytes() != 0) {
            usedNetInterfaceStat = interfaceStat;
            break;
        }
    }

    if (usedNetInterfaceStat != null) {
        long speed = usedNetInterfaceStat.getSpeed();
        sender.sendMessage(PRIMARY_COLOR + "Net Speed: " + SECONDARY_COLOR + Sigar.formatSize(speed));

        long receivedBytes = usedNetInterfaceStat.getRxBytes();
        long sentBytes = usedNetInterfaceStat.getTxBytes();
        sender.sendMessage(PRIMARY_COLOR + "Net Rec: " + SECONDARY_COLOR + Sigar.formatSize(receivedBytes));
        sender.sendMessage(PRIMARY_COLOR + "Net Sent: " + SECONDARY_COLOR + Sigar.formatSize(sentBytes));
    }
}
 
開發者ID:games647,項目名稱:LagMonitor,代碼行數:23,代碼來源:NativeCommand.java

示例3: getCpuTotal

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
public void getCpuTotal() {
	Sigar sigar = new Sigar();
	CpuInfo[] infos;
	try {
		infos = sigar.getCpuInfoList();
		for (int i = 0; i < infos.length; i++) {// 不管是單塊CPU還是多CPU都適用
			CpuInfo info = infos[i];
			System.out.println("CPU的總量:" + info.getMhz());// CPU的總量MHz
			System.out.println("獲得CPU的賣主:" + info.getVendor());// 獲得CPU的賣主,如:Intel
			System.out.println("CPU的類別:" + info.getModel());// 獲得CPU的類別,如:Celeron
			System.out.println("緩衝存儲器數量:" + info.getCacheSize());// 緩衝存儲器數量
			System.out.println("**************");
		}
	} catch (SigarException e) {
		e.printStackTrace();
	}
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:18,代碼來源:SysInfo.java

示例4: getPlatformName

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
/**
 * 3.操作係統信息
 */

// a)取到當前操作係統的名稱:
public String getPlatformName() {
	String hostname = "";
	try {
		hostname = InetAddress.getLocalHost().getHostName();
	} catch (Exception exc) {
		Sigar sigar = new Sigar();
		try {
			hostname = sigar.getNetInfo().getHostName();
		} catch (SigarException e) {
			hostname = "localhost.unknown";
		} finally {
			sigar.close();
		}
	}
	return hostname;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:22,代碼來源:SysInfo.java

示例5: testWho

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
public void testWho() {
	try {
		Sigar sigar = new Sigar();
		Who[] who = sigar.getWhoList();
		if (who != null && who.length > 0) {
			for (int i = 0; i < who.length; i++) {
				System.out.println("\n~~~~~~~~~" + String.valueOf(i) + "~~~~~~~~~");
				Who _who = who[i];
				System.out.println("獲取設備getDevice() = " + _who.getDevice());
				System.out.println("獲得主機getHost() = " + _who.getHost());
				System.out.println("獲取的時間getTime() = " + _who.getTime());
				// 當前係統進程表中的用戶名
				System.out.println("獲取用戶getUser() = " + _who.getUser());
			}
		}
	} catch (SigarException e) {
		e.printStackTrace();
	}
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:20,代碼來源:SysInfo.java

示例6: constructProcessStartCommand

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
private static String constructProcessStartCommand(
                                                    Sigar sigar,
                                                    long pid ) {

    StringBuilder startCommand = new StringBuilder();
    try {
        String[] processArgs = sigar.getProcArgs(pid);
        for (String arg : processArgs) {
            startCommand.append(arg);
            startCommand.append(" ");
        }
        return startCommand.toString();
    } catch (SigarException e) {
        // some system processes can not be accessed
        return null;
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:18,代碼來源:ReadingInstancesFactory.java

示例7: onCommand

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!isAllowed(sender, command)) {
        sender.sendMessage(org.bukkit.ChatColor.DARK_RED + "Not whitelisted");
        return true;
    }

    if (!plugin.getConfig().getBoolean("native-library")) {
        sender.sendMessage(ChatColor.DARK_RED + "Native support is disabled");
        return true;
    }

    //swap and load is already available in the environment command because MBeans already supports this
    Sigar sigar = plugin.getNativeData().getSigar();
    try {
        int uptime = (int) sigar.getUptime().getUptime();
        sender.sendMessage(PRIMARY_COLOR + "OS Uptime: " + SECONDARY_COLOR + formatUptime(uptime));

        CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
        int mhz = cpuInfoList[0].getMhz();
        sender.sendMessage(PRIMARY_COLOR + "CPU MHZ: " + SECONDARY_COLOR + mhz);

        CpuPerc cpuPerc = sigar.getCpuPerc();
        //IO wait
        double wait = cpuPerc.getWait();
        sender.sendMessage(PRIMARY_COLOR + "CPU Wait (I/O): " + SECONDARY_COLOR + wait + '%');

        Mem mem = sigar.getMem();
        //included cache
        long actualUsed = mem.getActualUsed();
        long used = mem.getUsed();

        long cache = used - actualUsed;
        sender.sendMessage(PRIMARY_COLOR + "Memory Cache: " + SECONDARY_COLOR + Sigar.formatSize(cache));

        printNetworkInfo(sender, sigar);

        //disk read write
        List<String> diskNames = Arrays.stream(sigar.getFileSystemList())
                .map(FileSystem::getDevName)
                .filter(name -> name.startsWith("/dev/sd"))
                .distinct()
                .collect(Collectors.toList());

        Collection<DiskUsage> diskUsages = new ArrayList<>();
        for (String diskName : diskNames) {
            diskUsages.add(sigar.getDiskUsage(diskName));
        }

        long diskReads = diskUsages.stream().mapToLong(DiskUsage::getReadBytes).sum();
        long diskWrites = diskUsages.stream().mapToLong(DiskUsage::getWriteBytes).sum();


        String diskReadBytes = Sigar.formatSize(diskReads);
        String diskWriteBytes = Sigar.formatSize(diskWrites);

        sender.sendMessage(PRIMARY_COLOR + "Disk read bytes: " + SECONDARY_COLOR + diskReadBytes);
        sender.sendMessage(PRIMARY_COLOR + "Disk write bytes: " + SECONDARY_COLOR + diskWriteBytes);

        sender.sendMessage(PRIMARY_COLOR + "Filesystems:");
        for (FileSystem fileSystem : sigar.getFileSystemList()) {
            String dirName = fileSystem.getDirName();
            String typeName = fileSystem.getSysTypeName();
            sender.sendMessage(PRIMARY_COLOR + dirName + " - " + SECONDARY_COLOR + typeName);
        }
    } catch (SigarException sigarException) {
        plugin.getLogger().log(Level.SEVERE, null, sigarException);
    }

    return true;
}
 
開發者ID:games647,項目名稱:LagMonitor,代碼行數:72,代碼來源:NativeCommand.java

示例8: getStats

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
public MachineStats getStats(Sigar sigar) {
    CpuStats cpuStats = CpuStats.builder()
                                .build();
    SwapStats swapStats = SwapStats.builder()
                                   .build();
    MemoryStats memoryStats = MemoryStats.builder()
                                         .build();
    try {
        swapStats = getSwapStats(sigar);
        cpuStats = getCpuStats(sigar);
        getMemoryStats(sigar);

    } catch (SigarException | UnsatisfiedLinkError e) {
        logger.error("Error during sigar stats operation", e);
    } finally {
        sigar.close();
    }

    return getMachineStats(swapStats, cpuStats, memoryStats);

}
 
開發者ID:aol,項目名稱:micro-server,代碼行數:22,代碼來源:MachineStatsChecker.java

示例9: updateMachineInfo

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
@Override
public MachineInfo updateMachineInfo(MachineInfo info)
{
    Sigar sigar = new Sigar();
	long maxMemory = Runtime.getRuntime().maxMemory();
	long totalMemory = Runtime.getRuntime().totalMemory();
	long freeMemory = Runtime.getRuntime().freeMemory();
	info.setUsedMaxMemoryUsage((float) ((double) (maxMemory - freeMemory) / (double) maxMemory));
	info.setUsedTotalMemoryUsage((float) ((double) (totalMemory - freeMemory) / (double) totalMemory));
       Mem memory = null;
       try {
           memory = sigar.getMem();
           info.setUsedPhysicalMemoryUsage((float)((double) memory.getUsed() / (double)memory.getTotal()));
       } catch (SigarException e) {
           log.error(e.getMessage(), e);
       }
	updateProcessCpuUsage(sigar, info);
	updateSystemCpuUsage(sigar, info);
	info.setHealthyScore(NodeHealth.evaluateLocal(info));
	return info;
}
 
開發者ID:liulhdarks,項目名稱:darks-grid,代碼行數:22,代碼來源:SigarMachineInfoFactory.java

示例10: calculateStats

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
public void calculateStats() {
    numCores = Runtime.getRuntime().availableProcessors();
    Sigar sigar = new Sigar();
    try {
        CpuInfo[] cpuInfo = sigar.getCpuInfoList();
        cpuFreq = cpuInfo[0].getMhz();
        Mem memInfo = sigar.getMem();
        freeRAM = memInfo.getFreePercent();
        cpuLoad = sigar.getLoadAverage();
        for (int i = 0; i < getCpuLoad().length; i++) {
            cpuLoad[i] /= numCores;
        }
    } catch (SigarException ex) {
        ex.printStackTrace();
    }
}
 
開發者ID:adityashah30,項目名稱:dcs,代碼行數:17,代碼來源:StatsCalculator.java

示例11: shutdown

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
static void shutdown(final Sigar sigar) {
	LOG.info("Shutting down perfMon...");

	String[] type = new String[] { "State.Name.sw=java,Args.*.re=perf(m|M)on" };

	try {
		long ownPid = sigar.getPid();
		long[] pids = Shell.getPids(sigar, type);
		for (long pid : pids) {
			if (pid != ownPid) {
				LOG.info("Sending SIGTERM signal to perfMon process with PID {}", pid);
				sigar.kill(pid, "TERM");
			}
		}
	} catch (SigarException ex) {
		LOG.error(ex.getMessage(), ex);
	}
}
 
開發者ID:mgm-tp,項目名稱:perfload-perfmon,代碼行數:19,代碼來源:PerfMon.java

示例12: testParseProcesses

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
@Test
public void testParseProcesses() {
    Map<String, ?> configArgs = YmlReader.readFromFile(new File("src/test/resources/conf/config-windows.yml"));
    Mockito.doReturn(processList).when(parser).fetchProcessListFromSigar();
    Mockito.doReturn(20.0).when(parser).getProcCPU((Sigar) Mockito.anyObject(), Mockito.anyString());
    Mockito.doReturn(Long.valueOf(20)).when(parser).getProcMem((Sigar) Mockito.anyObject(), Mockito.anyString());
    Map<String, ProcessData> processDataMap = parser.fetchMetrics(configArgs);

    Map<String, String> dockerProcessData = processDataMap.get("docker").getProcessMetrics();
    Assert.assertEquals(String.valueOf(0), dockerProcessData.get(MonitorConstants.RUNNING_INSTANCES_COUNT));

    Map<String, String> svchostProcessData = processDataMap.get("svchost").getProcessMetrics();
    Assert.assertEquals(String.valueOf(11), svchostProcessData.get(MonitorConstants.RUNNING_INSTANCES_COUNT));

    Map<String, String> svchostFilteredData = processDataMap.get("svchostFiltered").getProcessMetrics();
    Assert.assertEquals(String.valueOf(1), svchostFilteredData.get(MonitorConstants.RUNNING_INSTANCES_COUNT));

    Map<String, String> javaProcessData = processDataMap.get("java").getProcessMetrics();
    Assert.assertEquals(String.valueOf(2), javaProcessData.get(MonitorConstants.RUNNING_INSTANCES_COUNT));

    Map<String, String> machineAgentProcessData = processDataMap.get("MachineAgent").getProcessMetrics();
    Assert.assertEquals(String.valueOf(1), machineAgentProcessData.get(MonitorConstants.RUNNING_INSTANCES_COUNT));

    Map<String, String> notepadProcessData = processDataMap.get("Notepad").getProcessMetrics();
    Assert.assertEquals(String.valueOf(1), notepadProcessData.get(MonitorConstants.RUNNING_INSTANCES_COUNT));
}
 
開發者ID:Appdynamics,項目名稱:process-monitoring-extension,代碼行數:27,代碼來源:WindowsParserTest.java

示例13: main

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    Sigar sigar = new Sigar();

    if (args.length != 1) {
        throw new Exception("Usage: MemWatch pid");
    }

    long pid = Long.parseLong(args[0]);

    long lastTime = System.currentTimeMillis();

    ProcMem last = sigar.getProcMem(pid);

    while (true) {
        ProcMem cur = sigar.getProcMem(pid);
        
        StringBuffer diff = diff(last, cur);

        if (diff.length() == 0) {
            System.out.println("no change " +
                               "(size=" +
                               Sigar.formatSize(cur.getSize()) +
                               ")");
        }
        else {
            long curTime = System.currentTimeMillis();
            long timeDiff = curTime - lastTime;
            lastTime = curTime;
            diff.append(" after " + timeDiff + "ms");
            System.out.println(diff);
        }

        last = cur;
        Thread.sleep(SLEEP_TIME);
    }
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:37,代碼來源:MemWatch.java

示例14: output

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
public void output(String[] args) throws SigarException {
    org.hyperic.sigar.CpuInfo[] infos =
        this.sigar.getCpuInfoList();

    CpuPerc[] cpus =
        this.sigar.getCpuPercList();

    org.hyperic.sigar.CpuInfo info = infos[0];
    long cacheSize = info.getCacheSize();
    println("Vendor........." + info.getVendor());
    println("Model.........." + info.getModel());
    println("Mhz............" + info.getMhz());
    println("Total CPUs....." + info.getTotalCores());
    if ((info.getTotalCores() != info.getTotalSockets()) ||
        (info.getCoresPerSocket() > info.getTotalCores()))
    {
        println("Physical CPUs.." + info.getTotalSockets());
        println("Cores per CPU.." + info.getCoresPerSocket());
    }

    if (cacheSize != Sigar.FIELD_NOTIMPL) {
        println("Cache size...." + cacheSize);
    }
    println("");

    if (!this.displayTimes) {
        return;
    }

    for (int i=0; i<cpus.length; i++) {
        println("CPU " + i + ".........");
        output(cpus[i]);
    }

    println("Totals........");
    output(this.sigar.getCpuPerc());
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:38,代碼來源:CpuInfo.java

示例15: getenv

import org.hyperic.sigar.Sigar; //導入依賴的package包/類
private static String getenv(String key) {
    try {
        return System.getenv("ANT_HOME"); //check for junit.jar
    } catch (Error e) {
        /*1.4*/
        Sigar sigar = new Sigar();
        try {
            return sigar.getProcEnv("$$", "ANT_HOME");
        } catch (Exception se) {
            return null;
        }
        finally { sigar.close(); }
    }
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:15,代碼來源:Runner.java


注:本文中的org.hyperic.sigar.Sigar類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。