Skip to content

Commit

Permalink
Now gathers physical CPU and RAM data to close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
phrack committed Dec 20, 2015
1 parent ee38879 commit 9c055a5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ repositories {
}

dependencies {
// OSHI to collect HW and system state data
compile group: 'com.github.dblock', name: 'oshi-core', version: '2.+'

// Raven, exception reporting client (requires logback)
compile group: 'net.kencochrane.raven', name: 'raven-logback', version: '6.+'

Expand Down
27 changes: 25 additions & 2 deletions src/main/java/com/shootoff/diagnostics/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,35 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import oshi.SystemInfo;

public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static final long BYTES_IN_MEGABYTE = 1048576;
private static final long SHOOTOFF_PROCESS_TIMEOUT = 15000; // ms

public static void main(String[] args) throws IOException, InterruptedException {
SystemInfo si = new SystemInfo();

StringBuilder cpuLoadPerProcessor = new StringBuilder("CPU Load Per Processor:");

for (double load : si.getHardware().getProcessor().getProcessorCpuLoadBetweenTicks()) {
cpuLoadPerProcessor.append(" ");
cpuLoadPerProcessor.append(String.format("%.02f", load * 100));
cpuLoadPerProcessor.append("%");
}

String cpuData = String.format("%s%n is64bit = %b%n physical cpu(s): %d%n logical cpu(s): %d%n%s",
si.getHardware().getProcessor().getName(),
si.getHardware().getProcessor().isCpu64bit(),
si.getHardware().getProcessor().getPhysicalProcessorCount(),
si.getHardware().getProcessor().getLogicalProcessorCount(),
cpuLoadPerProcessor);

String ramData = String.format("Total RAM Installed: %d MB%nAvailable RAM: %d MB",
si.getHardware().getMemory().getTotal() / BYTES_IN_MEGABYTE,
si.getHardware().getMemory().getAvailable() / BYTES_IN_MEGABYTE);

String runtimeName = System.getProperty("java.runtime.name");
String runtimeVersion = System.getProperty("java.runtime.version");
String jvmBitness = System.getProperty("sun.arch.data.model");
Expand All @@ -47,8 +70,8 @@ public static void main(String[] args) throws IOException, InterruptedException
long maxMemory = Runtime.getRuntime().maxMemory() / BYTES_IN_MEGABYTE;
String memoryAvailableToJVM = String.format("Max amount of memory JVM will use = %d MB", maxMemory);

String diagnosticData = String.format("%s%n%s%n%s%n%n%s", runtimeData, osData,
memoryAvailableToJVM, getShootOFFOutput());
String diagnosticData = String.format("%s%n%s%n%s%n%s%n%s%n%s%n", runtimeData, osData,
memoryAvailableToJVM, cpuData, ramData, getShootOFFOutput());

logger.error(diagnosticData);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<appender name="Sentry" class="net.kencochrane.raven.logback.SentryAppender">
<dsn>http://e125530c2ca249bd956343ca2ad09dd4:c34458865bef486195a6b0341e95e3de@dev.shootoffapp.com:9000/1</dsn>
<tags>shootoff-diagnostic-tool:1.0</tags>
<tags>shootoff-diagnostic-tool:1.1</tags>
</appender>

<root level="warn">
Expand Down

0 comments on commit 9c055a5

Please sign in to comment.