• ■ ■ ■ ■ ■ ■
    src/main/java/io/onedev/agent/Agent.java
    skipped 34 lines
    35 35  import io.onedev.commons.utils.FileUtils;
    36 36  import io.onedev.commons.utils.command.Commandline;
    37 37  import io.onedev.commons.utils.command.LineConsumer;
     38 +import oshi.SystemInfo;
     39 +import oshi.hardware.HardwareAbstractionLayer;
    38 40   
    39 41  public class Agent {
    40 42   
    skipped 70 lines
    111 113  
    112 114   private static volatile WebSocketClient client;
    113 115  
    114  - @SuppressWarnings("restriction")
    115 116   public static void main(String[] args) throws Exception {
    116 117   thread = Thread.currentThread();
    117 118  
    skipped 137 lines
    255 256   if (StringUtils.isBlank(token))
    256 257   throw new ExplicitException("Property '" + AGENT_TOKEN_KEY + "' not specified");
    257 258  
     259 + HardwareAbstractionLayer hardware = new SystemInfo().getHardware();
     260 +
    258 261   String cpuString = System.getenv(AGENT_CPU_KEY);
    259 262   if (StringUtils.isBlank(cpuString))
    260 263   cpuString = System.getProperty(AGENT_CPU_KEY);
    261 264   if (StringUtils.isBlank(cpuString))
    262 265   cpuString = props.getProperty(AGENT_CPU_KEY);
    263 266   if (StringUtils.isBlank(cpuString)) {
    264  - cpu = Runtime.getRuntime().availableProcessors()*1000;
     267 + cpu = hardware.getProcessor().getLogicalProcessorCount()*1000;
    265 268   } else {
    266 269   try {
    267 270   cpu = Integer.parseInt(cpuString);
    skipped 8 lines
    276 279   if (StringUtils.isBlank(memoryString))
    277 280   memoryString = props.getProperty(AGENT_MEMORY_KEY);
    278 281   if (StringUtils.isBlank(memoryString)) {
    279  - com.sun.management.OperatingSystemMXBean os = (com.sun.management.OperatingSystemMXBean)
    280  - java.lang.management.ManagementFactory.getOperatingSystemMXBean();
    281  - memory = (int)(os.getTotalPhysicalMemorySize()/1024/1024);
     282 + memory = (int) (hardware.getMemory().getTotal()/1024/1024);
    282 283   } else {
    283 284   try {
    284 285   memory = Integer.parseInt(memoryString);
    skipped 189 lines
Please wait...
Page is in error, reload to recover