Ver código fonte

add util to get memory stats

tags/2.0.1
Jonathan Cobb 4 anos atrás
pai
commit
5165445487
2 arquivos alterados com 13 adições e 0 exclusões
  1. +7
    -0
      pom.xml
  2. +6
    -0
      src/main/java/org/cobbzilla/util/system/CommandShell.java

+ 7
- 0
pom.xml Ver arquivo

@@ -373,6 +373,13 @@ cobbzilla-utils is available under the Apache License, version 2: http://www.apa
<version>1.64</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.github.oshi/oshi-core -->
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>5.2.4</version>
</dependency>

</dependencies>

<build>


+ 6
- 0
src/main/java/org/cobbzilla/util/system/CommandShell.java Ver arquivo

@@ -6,6 +6,8 @@ import org.apache.commons.exec.*;
import org.apache.commons.io.output.TeeOutputStream;
import org.cobbzilla.util.collection.MapBuilder;
import org.cobbzilla.util.io.FileUtil;
import oshi.SystemInfo;
import oshi.hardware.HardwareAbstractionLayer;

import java.io.*;
import java.util.*;
@@ -27,6 +29,8 @@ public class CommandShell {
public static final String CHOWN = "chown";

private static final int[] DEFAULT_EXIT_VALUES = {0};
public static final SystemInfo SYSTEM_INFO = new SystemInfo();
public static final HardwareAbstractionLayer HARDWARE = SYSTEM_INFO.getHardware();

public static Map<String, String> loadShellExports (String path) throws IOException {
if (!path.startsWith("/")) {
@@ -254,6 +258,8 @@ public class CommandShell {
}
}

public static final long totalSystemMemory() { return HARDWARE.getMemory().getTotal(); }

public static String hostname () { return toString("hostname"); }
public static String domainname() { return toString("hostname -d"); }
public static String hostname_short() { return toString("hostname -s"); }


Carregando…
Cancelar
Salvar