use of org.apache.nifi.controller.status.history.GarbageCollectionHistory in project nifi by apache.
the class DtoFactory method createJvmDiagnosticsSnapshotDto.
private JVMDiagnosticsSnapshotDTO createJvmDiagnosticsSnapshotDto(final FlowController flowController) {
final JVMDiagnosticsSnapshotDTO dto = new JVMDiagnosticsSnapshotDTO();
final JVMControllerDiagnosticsSnapshotDTO controllerDiagnosticsDto = new JVMControllerDiagnosticsSnapshotDTO();
final JVMFlowDiagnosticsSnapshotDTO flowDiagnosticsDto = new JVMFlowDiagnosticsSnapshotDTO();
final JVMSystemDiagnosticsSnapshotDTO systemDiagnosticsDto = new JVMSystemDiagnosticsSnapshotDTO();
dto.setControllerDiagnostics(controllerDiagnosticsDto);
dto.setFlowDiagnosticsDto(flowDiagnosticsDto);
dto.setSystemDiagnosticsDto(systemDiagnosticsDto);
final SystemDiagnostics systemDiagnostics = flowController.getSystemDiagnostics();
// flow-related information
final Set<BundleDTO> bundlesLoaded = ExtensionManager.getAllBundles().stream().map(bundle -> bundle.getBundleDetails().getCoordinate()).sorted((a, b) -> a.getCoordinate().compareTo(b.getCoordinate())).map(this::createBundleDto).collect(Collectors.toCollection(LinkedHashSet::new));
flowDiagnosticsDto.setActiveEventDrivenThreads(flowController.getActiveEventDrivenThreadCount());
flowDiagnosticsDto.setActiveTimerDrivenThreads(flowController.getActiveTimerDrivenThreadCount());
flowDiagnosticsDto.setBundlesLoaded(bundlesLoaded);
flowDiagnosticsDto.setTimeZone(System.getProperty("user.timezone"));
flowDiagnosticsDto.setUptime(FormatUtils.formatHoursMinutesSeconds(systemDiagnostics.getUptime(), TimeUnit.MILLISECONDS));
// controller-related information
controllerDiagnosticsDto.setClusterCoordinator(flowController.isClusterCoordinator());
controllerDiagnosticsDto.setPrimaryNode(flowController.isPrimary());
controllerDiagnosticsDto.setMaxEventDrivenThreads(flowController.getMaxEventDrivenThreadCount());
controllerDiagnosticsDto.setMaxTimerDrivenThreads(flowController.getMaxTimerDrivenThreadCount());
// system-related information
systemDiagnosticsDto.setMaxOpenFileDescriptors(systemDiagnostics.getMaxOpenFileHandles());
systemDiagnosticsDto.setOpenFileDescriptors(systemDiagnostics.getOpenFileHandles());
systemDiagnosticsDto.setPhysicalMemoryBytes(systemDiagnostics.getTotalPhysicalMemory());
systemDiagnosticsDto.setPhysicalMemory(FormatUtils.formatDataSize(systemDiagnostics.getTotalPhysicalMemory()));
final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
percentageFormat.setMaximumFractionDigits(2);
final Set<RepositoryUsageDTO> contentRepoUsage = new HashSet<>();
for (final Map.Entry<String, StorageUsage> entry : systemDiagnostics.getContentRepositoryStorageUsage().entrySet()) {
final String repoName = entry.getKey();
final StorageUsage usage = entry.getValue();
final RepositoryUsageDTO usageDto = new RepositoryUsageDTO();
usageDto.setName(repoName);
usageDto.setFileStoreHash(DigestUtils.sha256Hex(flowController.getContentRepoFileStoreName(repoName)));
usageDto.setFreeSpace(FormatUtils.formatDataSize(usage.getFreeSpace()));
usageDto.setFreeSpaceBytes(usage.getFreeSpace());
usageDto.setTotalSpace(FormatUtils.formatDataSize(usage.getTotalSpace()));
usageDto.setTotalSpaceBytes(usage.getTotalSpace());
final double usedPercentage = (usage.getTotalSpace() - usage.getFreeSpace()) / (double) usage.getTotalSpace();
final String utilization = percentageFormat.format(usedPercentage);
usageDto.setUtilization(utilization);
contentRepoUsage.add(usageDto);
}
final Set<RepositoryUsageDTO> provRepoUsage = new HashSet<>();
for (final Map.Entry<String, StorageUsage> entry : systemDiagnostics.getProvenanceRepositoryStorageUsage().entrySet()) {
final String repoName = entry.getKey();
final StorageUsage usage = entry.getValue();
final RepositoryUsageDTO usageDto = new RepositoryUsageDTO();
usageDto.setName(repoName);
usageDto.setFileStoreHash(DigestUtils.sha256Hex(flowController.getProvenanceRepoFileStoreName(repoName)));
usageDto.setFreeSpace(FormatUtils.formatDataSize(usage.getFreeSpace()));
usageDto.setFreeSpaceBytes(usage.getFreeSpace());
usageDto.setTotalSpace(FormatUtils.formatDataSize(usage.getTotalSpace()));
usageDto.setTotalSpaceBytes(usage.getTotalSpace());
final double usedPercentage = (usage.getTotalSpace() - usage.getFreeSpace()) / (double) usage.getTotalSpace();
final String utilization = percentageFormat.format(usedPercentage);
usageDto.setUtilization(utilization);
provRepoUsage.add(usageDto);
}
final RepositoryUsageDTO flowFileRepoUsage = new RepositoryUsageDTO();
for (final Map.Entry<String, StorageUsage> entry : systemDiagnostics.getProvenanceRepositoryStorageUsage().entrySet()) {
final String repoName = entry.getKey();
final StorageUsage usage = entry.getValue();
flowFileRepoUsage.setName(repoName);
flowFileRepoUsage.setFileStoreHash(DigestUtils.sha256Hex(flowController.getFlowRepoFileStoreName()));
flowFileRepoUsage.setFreeSpace(FormatUtils.formatDataSize(usage.getFreeSpace()));
flowFileRepoUsage.setFreeSpaceBytes(usage.getFreeSpace());
flowFileRepoUsage.setTotalSpace(FormatUtils.formatDataSize(usage.getTotalSpace()));
flowFileRepoUsage.setTotalSpaceBytes(usage.getTotalSpace());
final double usedPercentage = (usage.getTotalSpace() - usage.getFreeSpace()) / (double) usage.getTotalSpace();
final String utilization = percentageFormat.format(usedPercentage);
flowFileRepoUsage.setUtilization(utilization);
}
systemDiagnosticsDto.setContentRepositoryStorageUsage(contentRepoUsage);
systemDiagnosticsDto.setCpuCores(systemDiagnostics.getAvailableProcessors());
systemDiagnosticsDto.setCpuLoadAverage(systemDiagnostics.getProcessorLoadAverage());
systemDiagnosticsDto.setFlowFileRepositoryStorageUsage(flowFileRepoUsage);
systemDiagnosticsDto.setMaxHeapBytes(systemDiagnostics.getMaxHeap());
systemDiagnosticsDto.setMaxHeap(FormatUtils.formatDataSize(systemDiagnostics.getMaxHeap()));
systemDiagnosticsDto.setProvenanceRepositoryStorageUsage(provRepoUsage);
// Create the Garbage Collection History info
final GarbageCollectionHistory gcHistory = flowController.getGarbageCollectionHistory();
final List<GarbageCollectionDiagnosticsDTO> gcDiagnostics = new ArrayList<>();
for (final String memoryManager : gcHistory.getMemoryManagerNames()) {
final List<GarbageCollectionStatus> statuses = gcHistory.getGarbageCollectionStatuses(memoryManager);
final List<GCDiagnosticsSnapshotDTO> gcSnapshots = new ArrayList<>();
for (final GarbageCollectionStatus status : statuses) {
final GCDiagnosticsSnapshotDTO snapshotDto = new GCDiagnosticsSnapshotDTO();
snapshotDto.setTimestamp(status.getTimestamp());
snapshotDto.setCollectionCount(status.getCollectionCount());
snapshotDto.setCollectionMillis(status.getCollectionMillis());
gcSnapshots.add(snapshotDto);
}
final GarbageCollectionDiagnosticsDTO gcDto = new GarbageCollectionDiagnosticsDTO();
gcDto.setMemoryManagerName(memoryManager);
gcDto.setSnapshots(gcSnapshots);
gcDiagnostics.add(gcDto);
}
systemDiagnosticsDto.setGarbageCollectionDiagnostics(gcDiagnostics);
return dto;
}
Aggregations