use of org.apache.geode.management.internal.cli.util.BytesToString in project geode by apache.
the class ExportLogsCommand method checkIfExportLogsOverflowsDisk.
/**
* @throws ManagementException if export file size checking is enabled (fileSizeLimit > 0) and the
* space required on a cluster member to filter and zip up files to be exported exceeds
* the disk space available
*/
void checkIfExportLogsOverflowsDisk(String memberName, long fileSizeLimitBytes, long estimatedSize, long diskAvailable) {
if (fileSizeLimitBytes > 0) {
StringBuilder sb = new StringBuilder();
BytesToString bytesToString = new BytesToString();
if (estimatedSize > diskAvailable) {
sb.append("Estimated disk space required (").append(bytesToString.of(estimatedSize)).append(") to consolidate logs on member ").append(memberName).append(" will exceed available disk space (").append(bytesToString.of(diskAvailable)).append(")");
// FileTooBigException
throw new ManagementException(sb.toString());
}
}
}
use of org.apache.geode.management.internal.cli.util.BytesToString in project geode by apache.
the class GarbageCollectionFunction method execute.
@Override
public void execute(FunctionContext context) {
BytesToString bytesToString = new BytesToString();
Map<String, String> resultMap = null;
try {
Cache cache = CacheFactory.getAnyInstance();
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
long freeMemoryBeforeGC = Runtime.getRuntime().freeMemory();
long totalMemoryBeforeGC = Runtime.getRuntime().totalMemory();
long timeBeforeGC = System.currentTimeMillis();
Runtime.getRuntime().gc();
long freeMemoryAfterGC = Runtime.getRuntime().freeMemory();
long totalMemoryAfterGC = Runtime.getRuntime().totalMemory();
long timeAfterGC = System.currentTimeMillis();
resultMap = new HashMap<>();
resultMap.put("MemberId", member.getId());
resultMap.put("HeapSizeBeforeGC", bytesToString.of(totalMemoryBeforeGC - freeMemoryBeforeGC));
resultMap.put("HeapSizeAfterGC", bytesToString.of(totalMemoryAfterGC - freeMemoryAfterGC));
resultMap.put("TimeSpentInGC", String.valueOf(timeAfterGC - timeBeforeGC));
} catch (Exception ex) {
String message = "Exception in GC:" + ex.getMessage() + CliUtil.stackTraceAsString(ex);
context.getResultSender().lastResult(message);
}
context.getResultSender().lastResult(resultMap);
}
use of org.apache.geode.management.internal.cli.util.BytesToString in project geode by apache.
the class SizeExportLogsFunction method execute.
@Override
public void execute(final FunctionContext context) {
try {
InternalCache cache = GemFireCacheImpl.getInstance();
DistributionConfig config = cache.getInternalDistributedSystem().getConfig();
Args args = (Args) context.getArguments();
long diskAvailable = getDiskAvailable(config);
long estimatedSize = estimateLogFileSize(cache.getMyId(), config.getLogFile(), config.getStatisticArchiveFile(), args);
BytesToString bytesToString = new BytesToString();
if (estimatedSize == 0 || estimatedSize < diskAvailable) {
context.getResultSender().lastResult(Arrays.asList(estimatedSize));
} else {
StringBuilder sb = new StringBuilder().append("Estimated disk space required (").append(bytesToString.of(estimatedSize)).append(") to consolidate logs on member ").append(cache.getName()).append(" will exceed available disk space (").append(bytesToString.of(diskAvailable)).append(")");
// FileTooBigException
context.getResultSender().sendException(new ManagementException(sb.toString()));
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e.getMessage());
context.getResultSender().sendException(e);
}
}
Aggregations