本文整理汇总了Java中oshi.hardware.Processor类的典型用法代码示例。如果您正苦于以下问题:Java Processor类的具体用法?Java Processor怎么用?Java Processor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Processor类属于oshi.hardware包,在下文中一共展示了Processor类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: publishCpuPerc
import oshi.hardware.Processor; //导入依赖的package包/类
private void publishCpuPerc(final Map<String, Object> sharedData) {
Processor[] cpus = m_processors;
for (int i = 0; i < cpus.length; i++) {
// User, nice, sys, idle
long[] cpuTicks = cpus[i].getProcessorCpuLoadTicks();
long user = Math.abs(m_cpuTicks[i][0] - cpuTicks[0]);
long nice = Math.abs(m_cpuTicks[i][1] - cpuTicks[1]);
long sys = Math.abs(m_cpuTicks[i][2] - cpuTicks[2]);
long idle = Math.abs(m_cpuTicks[i][3] - cpuTicks[3]);
long total = user + nice + sys + idle;
if (total > 0L) {
// User, nice, sys, idle, combined
String instance = INSTANCE_CPU_PREFIX + i;
publishMetric(sharedData, CPU_USER_PERC, 100.0d * user / total, instance);
publishMetric(sharedData, CPU_NICE_PERC, 100.0d * nice / total, instance);
publishMetric(sharedData, CPU_SYS_PERC, 100.0d * sys / total, instance);
publishMetric(sharedData, CPU_IDLE_PERC, 100.0d * idle / total, instance);
publishMetric(sharedData, CPU_COMBINED_PERC, 100.0d * (user + sys) / total, instance);
}
m_cpuTicks[i][0] = cpuTicks[0];
m_cpuTicks[i][1] = cpuTicks[1];
m_cpuTicks[i][2] = cpuTicks[2];
m_cpuTicks[i][3] = cpuTicks[3];
}
}
开发者ID:clidev,项目名称:spike.x,代码行数:32,代码来源:OshiMetrics.java
示例2: publishCpuLoad
import oshi.hardware.Processor; //导入依赖的package包/类
private void publishCpuLoad(final Map<String, Object> sharedData) {
Processor[] cpus = m_processors;
for (int i = 0; i < cpus.length; i++) {
double cpuLoad = m_processors[i].getProcessorCpuLoadBetweenTicks();
String instance = INSTANCE_CPU_PREFIX + i;
publishMetric(sharedData, CPU_LOAD_AVERAGE, cpuLoad, instance);
}
}
开发者ID:clidev,项目名称:spike.x,代码行数:10,代码来源:OshiMetrics.java
示例3: outputSysInfo
import oshi.hardware.Processor; //导入依赖的package包/类
private void outputSysInfo(final SystemInfo sysInfo) {
logger().info("======================================================");
logger().info("{}", sysInfo.getOperatingSystem());
logger().info("------------------------------------------------------");
HardwareAbstractionLayer hal = sysInfo.getHardware();
Processor[] cpus = hal.getProcessors();
logger().info("CPU count: {}", cpus.length);
int n = 0;
for (Processor cpu : cpus) {
logger().info("{}: {}", n++, cpu);
}
long memTotal = hal.getMemory().getTotal();
long memAvail = hal.getMemory().getAvailable();
long memUsed = memTotal - memAvail;
logger().info("Used memory: {}", FormatUtil.formatBytes(memUsed));
logger().info("Available memory: {}", FormatUtil.formatBytes(memAvail));
logger().info("Total memory: {}", FormatUtil.formatBytes(memTotal));
// This can explode in a NullPointerException (at sun.awt.shell.Win32ShellFolder2.access$200(Win32ShellFolder2.java:72))
try {
for (OSFileStore fs : hal.getFileStores()) {
logger().info("{} ({}) Used: {} Free: {} Total: {}",
fs.getName(),
fs.getDescription(),
FormatUtil.formatBytes(fs.getTotalSpace() - fs.getUsableSpace()),
FormatUtil.formatBytes(fs.getUsableSpace()),
FormatUtil.formatBytes(fs.getTotalSpace()));
}
} catch (Exception e) {
logger().error("Failed to retrieve file store information", e);
}
logger().info("======================================================");
}
开发者ID:clidev,项目名称:spike.x,代码行数:39,代码来源:Activator.java
示例4: publishLoadAverage
import oshi.hardware.Processor; //导入依赖的package包/类
private void publishLoadAverage(final Map<String, Object> sharedData) {
Processor[] cpus = m_processors;
publishMetric(sharedData, LOAD_AVERAGE, cpus[0].getSystemLoadAverage(), INSTANCE_TOTAL);
publishMetric(sharedData, LOAD_AVERAGE_PERC, 100.0d * cpus[0].getSystemLoadAverage(), INSTANCE_TOTAL);
}
开发者ID:clidev,项目名称:spike.x,代码行数:6,代码来源:OshiMetrics.java
示例5: publishUptime
import oshi.hardware.Processor; //导入依赖的package包/类
private void publishUptime(final Map<String, Object> sharedData) {
Processor[] cpus = m_processors;
publishMetric(sharedData, UPTIME, cpus[0].getSystemUptime());
}
开发者ID:clidev,项目名称:spike.x,代码行数:5,代码来源:OshiMetrics.java
示例6: testSystemInfo
import oshi.hardware.Processor; //导入依赖的package包/类
@Test
public void testSystemInfo() {
// OSHI supports Windows, OS X and Linux
if (HostOs.isWindows() || HostOs.isMac() || HostOs.isLinux()) {
// Operating system
SystemInfo si = new SystemInfo();
m_logger.info("{}", si.getOperatingSystem());
// Hardware: processors
HardwareAbstractionLayer hal = si.getHardware();
for (Processor cpu : hal.getProcessors()) {
m_logger.info("{}", cpu);
}
// Hardware: memory
m_logger.info("Available mem: {}", hal.getMemory().getAvailable());
m_logger.info("Total mem: {}", hal.getMemory().getTotal());
// Uptime
m_logger.info("Uptime: {}", hal.getProcessors()[0].getSystemUptime());
// Resolve ticks per second
outputSystemCpuLoad(hal, 1000L);
// Resolve ticks per 3 seconds
outputSystemCpuLoad(hal, 3000L);
// Per CPU load
outputProcessorLoad(hal, 1000L);
m_logger.info("CPU load: {} (ticks)",
hal.getProcessors()[0].getSystemCpuLoadBetweenTicks() * 100d);
m_logger.info("CPU load: {} (OS MXBean)",
hal.getProcessors()[0].getSystemCpuLoad() * 100d);
double loadAvg = hal.getProcessors()[0].getSystemLoadAverage();
m_logger.info("CPU load average: {}", (loadAvg < 0 ? "NA" : loadAvg));
// Hardware: filesystem
for (OSFileStore fs : hal.getFileStores()) {
m_logger.info("{} ({}) - used: {} free: {} total: {}",
fs.getName(),
fs.getDescription(),
FormatUtil.formatBytes(fs.getTotalSpace() - fs.getUsableSpace()),
FormatUtil.formatBytes(fs.getUsableSpace()),
FormatUtil.formatBytes(fs.getTotalSpace()));
}
}
VertxAssert.testComplete();
}
开发者ID:clidev,项目名称:spike.x,代码行数:54,代码来源:OshiTest.java
示例7: printSystemInfo
import oshi.hardware.Processor; //导入依赖的package包/类
/**
* Stalks your computer and prints the information about it using OSHI.
*
* <p>Just kidding, you don't need to call this, but it's helpful if you juset want to know.</p>
*/
public void printSystemInfo() {
// Obtains
// OS, java version, flags, CPU, disks, RAM, power
System.out.println("System info:");
String os = System.getProperty("os.name");
String osVer = System.getProperty("os.version");
String osArch = System.getProperty("os.arch");
System.out.printf("Running %s version %s arch %s\n", os, osVer, osArch);
String javaVer = System.getProperty("java.version");
String vmVendor = System.getProperty("java.vendor");
System.out.printf("Java version %s JVM %s\n", javaVer, vmVendor);
System.out.print("Java flags: ");
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();
for (String string : arguments) {
System.out.print(string + " ");
}
for (String arg : args) {
System.out.print(arg + " ");
}
System.out.println();
SystemInfo info = new SystemInfo();
HardwareAbstractionLayer layer = info.getHardware();
Memory memory = layer.getMemory();
System.out.printf("Memory total %d bytes, usable %d bytes\n", memory.getTotal(), memory.getAvailable());
Runtime runtime = Runtime.getRuntime();
System.out.printf("VM memory free %d bytes, max %d bytes, total %d bytes\n", runtime.freeMemory(),
runtime.maxMemory(), runtime.totalMemory());
Processor[] procs = layer.getProcessors();
System.out.println("CPUs (" + procs.length + "):");
for (Processor p : procs) {
System.out.printf(" %s\n", p.getName());
}
OSFileStore[] stores = layer.getFileStores();
System.out.print("Disks (" + stores.length + "):\n");
for (OSFileStore store : stores) {
System.out.printf(" %s cap %d bytes, usable %d bytes\n",
store.getName(), store.getTotalSpace(), store.getUsableSpace());
}
PowerSource[] sources = layer.getPowerSources();
System.out.println("PSUs (" + sources.length + "):");
for (PowerSource source : sources) {
System.out.printf(" %s: remaining cap %f, time left %f\n", source.getName(), source.getRemainingCapacity(),
source.getTimeRemaining());
}
}
开发者ID:AgentTroll,项目名称:Fastest-Fing-Data-Structure-Java,代码行数:61,代码来源:Benchmark.java
注:本文中的oshi.hardware.Processor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论