forked from apache/cassandra
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
review fixes and suggested improvements
- Loading branch information
1 parent
7163029
commit 4ff28f9
Showing
5 changed files
with
188 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ | |
* An abstraction of System information, this class provides access to system information without specifying how | ||
* it is retrieved. | ||
*/ | ||
public final class SystemInfo | ||
public class SystemInfo | ||
{ | ||
// TODO: Determine memlock limits if possible | ||
// TODO: Determine if file system is remote or local | ||
|
@@ -48,9 +48,14 @@ public final class SystemInfo | |
private static final Logger logger = LoggerFactory.getLogger(SystemInfo.class); | ||
|
||
private static final long INFINITY = -1L; | ||
private static final long EXPECTED_MIN_NOFILE = 10000L; // number of files that can be opened | ||
private static final long EXPECTED_NPROC = 32768L; // number of processes | ||
private static final long EXPECTED_AS = 0x7FFFFFFFL; // address space | ||
static final long EXPECTED_MIN_NUMBER_OF_OPENED_FILES = 10000L; // number of files that can be opened | ||
static final long EXPECTED_MIN_NUMBER_OF_PROCESSES = 32768L; // number of processes | ||
static final long EXPECTED_ADDRESS_SPACE = 0x7FFFFFFFL; // address space | ||
|
||
static final String OPEN_FILES_VIOLATION_MESSAGE = format("Minimum value for max open files should be >= %s. ", EXPECTED_MIN_NUMBER_OF_OPENED_FILES); | ||
static final String NUMBER_OF_PROCESSES_VIOLATION_MESSAGE = format("Number of processes should be >= %s. ", EXPECTED_MIN_NUMBER_OF_PROCESSES); | ||
static final String ADDRESS_SPACE_VIOLATION_MESSAGE = format("Amount of available address space should be >= %s. ", EXPECTED_ADDRESS_SPACE); | ||
static final String SWAP_VIOLATION_MESSAGE = "Swap should be disabled. "; | ||
|
||
/** | ||
* The default number of processes that are reported if the actual value can not be retrieved. | ||
|
@@ -59,30 +64,6 @@ public final class SystemInfo | |
|
||
private static final Pattern SPACES_PATTERN = Pattern.compile("\\s+"); | ||
|
||
private static Supplier<SystemInfo> provider = () -> new SystemInfo(); | ||
|
||
/** | ||
* Sets the Supplier of the SystemInfo. | ||
* <p> | ||
* If {@code null} is passed as the provider the provider will be reset to the default provider. | ||
* </p> | ||
* @param provider the Supplier of SystemInfo that will be used for {@code instance} calls. May be null. | ||
*/ | ||
public static void setProvider(Supplier<SystemInfo> provider) { | ||
SystemInfo.provider = provider == null ? () -> new SystemInfo() : provider; | ||
} | ||
|
||
/** | ||
* Gets an instance of SystemInfo. Whether the SystemInfo instance is new or memoized depends upon the | ||
* implementation of the provider specified by {@code setProvider}. By default a new version of SystemInfo | ||
* is created on every call. | ||
* @return | ||
*/ | ||
public static SystemInfo instance() | ||
{ | ||
return provider.get(); | ||
} | ||
|
||
/** | ||
* The oshi.SystemInfo has the following note: | ||
* Platform-specific Hardware and Software objects are retrieved via memoized suppliers. To conserve memory at the | ||
|
@@ -94,7 +75,6 @@ public static SystemInfo instance() | |
*/ | ||
private final oshi.SystemInfo si; | ||
|
||
// package private for testing | ||
SystemInfo() | ||
{ | ||
si = new oshi.SystemInfo(); | ||
|
@@ -137,9 +117,9 @@ public long getMaxProcess() | |
return "unlimited".equals(limit) ? INFINITY : Long.parseLong(limit); | ||
} | ||
} | ||
logger.error( "'Max processes' not found in "+path); | ||
logger.error("'Max processes' not found in {}", path); | ||
} | ||
catch (Throwable t) | ||
catch (Exception t) | ||
{ | ||
logger.error(format("Unable to read %s", path), t); | ||
} | ||
|
@@ -205,21 +185,21 @@ public Optional<String> isDegraded() | |
{ | ||
Supplier<String> expectedNumProc = () -> { | ||
// only check proc on nproc linux | ||
if (oshi.SystemInfo.getCurrentPlatform() == PlatformEnum.LINUX) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
smiklosovic
Author
|
||
return invalid(getMaxProcess(), EXPECTED_NPROC) ? format("Number of processes should be >= %s. ", EXPECTED_NPROC) | ||
: null; | ||
if (platform() == PlatformEnum.LINUX) | ||
return invalid(getMaxProcess(), EXPECTED_MIN_NUMBER_OF_PROCESSES) ? NUMBER_OF_PROCESSES_VIOLATION_MESSAGE | ||
: null; | ||
else | ||
return format("System is running %s, Linux OS is recommended", platform()); | ||
return format("System is running %s, Linux OS is recommended. ", platform()); | ||
}; | ||
|
||
Supplier<String> swapShouldBeDisabled = () -> (getSwapSize() > 0) ? "Swap should be disabled. " : null; | ||
Supplier<String> swapShouldBeDisabled = () -> (getSwapSize() > 0) ? SWAP_VIOLATION_MESSAGE : null; | ||
|
||
Supplier<String> expectedAddressSpace = () -> invalid(getVirtualMemoryMax(), EXPECTED_AS) | ||
? format("Amount of available address space should be >= %s. ", EXPECTED_AS) | ||
Supplier<String> expectedAddressSpace = () -> invalid(getVirtualMemoryMax(), EXPECTED_ADDRESS_SPACE) | ||
? ADDRESS_SPACE_VIOLATION_MESSAGE | ||
: null; | ||
|
||
Supplier<String> expectedMinNoFile = () -> invalid(getMaxOpenFiles(), EXPECTED_MIN_NOFILE) | ||
? format("Minimum value for max open files should be >= %s. ", EXPECTED_MIN_NOFILE) | ||
Supplier<String> expectedMinNoFile = () -> invalid(getMaxOpenFiles(), EXPECTED_MIN_NUMBER_OF_OPENED_FILES) | ||
? OPEN_FILES_VIOLATION_MESSAGE | ||
: null; | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
we do not need additional supplier for kernel version if we have a supplier for systeminfo