mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-14 17:06:16 +00:00
Add message if there is no timing data.
Improve some try with resources blocks.
This commit is contained in:
parent
c30120f437
commit
e3dc9f2f55
@ -983,23 +983,21 @@ public final class EnterpriseHealthMonitor implements PropertyChangeListener {
|
||||
throw new HealthMonitorException("Health Monitor is not enabled");
|
||||
}
|
||||
|
||||
CoordinationService.Lock lock = getSharedDbLock();
|
||||
if(lock == null) {
|
||||
throw new HealthMonitorException("Error getting database lock");
|
||||
}
|
||||
|
||||
try{
|
||||
try (CoordinationService.Lock lock = getSharedDbLock()) {
|
||||
if(lock == null) {
|
||||
throw new HealthMonitorException("Error getting database lock");
|
||||
}
|
||||
|
||||
Connection conn = connect();
|
||||
if(conn == null) {
|
||||
throw new HealthMonitorException("Error getting database connection");
|
||||
}
|
||||
ResultSet resultSet = null;
|
||||
|
||||
Map<String, List<DatabaseTimingResult>> resultMap = new HashMap<>();
|
||||
|
||||
try (Statement statement = conn.createStatement()) {
|
||||
|
||||
resultSet = statement.executeQuery("SELECT * FROM timing_data");
|
||||
try (Statement statement = conn.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery("SELECT * FROM timing_data")) {
|
||||
|
||||
while (resultSet.next()) {
|
||||
String name = resultSet.getString("name");
|
||||
DatabaseTimingResult timingResult = new DatabaseTimingResult(resultSet);
|
||||
@ -1016,25 +1014,14 @@ public final class EnterpriseHealthMonitor implements PropertyChangeListener {
|
||||
} catch (SQLException ex) {
|
||||
throw new HealthMonitorException("Error reading timing metrics from database", ex);
|
||||
} finally {
|
||||
if(resultSet != null) {
|
||||
try {
|
||||
resultSet.close();
|
||||
} catch (SQLException ex) {
|
||||
logger.log(Level.SEVERE, "Error closing result set", ex);
|
||||
}
|
||||
}
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
logger.log(Level.SEVERE, "Error closing Connection.", ex);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
lock.release();
|
||||
} catch (CoordinationService.CoordinationServiceException ex) {
|
||||
throw new HealthMonitorException("Error releasing database lock", ex);
|
||||
}
|
||||
} catch (CoordinationService.CoordinationServiceException ex) {
|
||||
throw new HealthMonitorException("Error getting database lock", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.healthmonitor;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
@ -166,8 +165,6 @@ public class HealthMonitorDashboard {
|
||||
emptyTimingMetricPanel.add(new JLabel(" "));
|
||||
emptyTimingMetricPanel.add(new JLabel(Bundle.HealthMonitorDashboard_createTimingPanel_noData()));
|
||||
|
||||
//timingMetricPanel.revalidate();
|
||||
//timingMetricPanel.repaint();
|
||||
return emptyTimingMetricPanel;
|
||||
}
|
||||
|
||||
@ -290,12 +287,19 @@ public class HealthMonitorDashboard {
|
||||
* Update the timing graphs.
|
||||
* @throws HealthMonitorException
|
||||
*/
|
||||
@NbBundle.Messages({"HealthMonitorDashboard.updateTimingMetricGraphs.noData=No data to display"})
|
||||
private void updateTimingMetricGraphs() throws HealthMonitorException {
|
||||
|
||||
// Clear out any old graphs
|
||||
graphPanel.removeAll();
|
||||
|
||||
for(String name:timingData.keySet()) {
|
||||
if(timingData.keySet().isEmpty()) {
|
||||
// There are no timing metrics in the database
|
||||
graphPanel.add(new JLabel(Bundle.HealthMonitorDashboard_updateTimingMetricGraphs_noData()));
|
||||
return;
|
||||
}
|
||||
|
||||
for(String metricName:timingData.keySet()) {
|
||||
|
||||
// If necessary, trim down the list of results to fit the selected time range
|
||||
List<EnterpriseHealthMonitor.DatabaseTimingResult> intermediateTimingDataForDisplay;
|
||||
@ -303,17 +307,19 @@ public class HealthMonitorDashboard {
|
||||
DateRange selectedDateRange = DateRange.fromLabel(dateComboBox.getSelectedItem().toString());
|
||||
if(selectedDateRange != DateRange.ALL) {
|
||||
long threshold = System.currentTimeMillis() - selectedDateRange.getTimestampRange();
|
||||
intermediateTimingDataForDisplay = timingData.get(name).stream()
|
||||
intermediateTimingDataForDisplay = timingData.get(metricName).stream()
|
||||
.filter(t -> t.getTimestamp() > threshold)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
intermediateTimingDataForDisplay = timingData.get(name);
|
||||
intermediateTimingDataForDisplay = timingData.get(metricName);
|
||||
}
|
||||
} else {
|
||||
intermediateTimingDataForDisplay = timingData.get(name);
|
||||
intermediateTimingDataForDisplay = timingData.get(metricName);
|
||||
}
|
||||
|
||||
// Get the name of the selected host, if there is one
|
||||
// Get the name of the selected host, if there is one.
|
||||
// The graph always uses the data from all hosts to generate the x and y scales
|
||||
// so we don't filter anything out here.
|
||||
String hostToDisplay = null;
|
||||
if(hostCheckBox.isSelected() && (hostComboBox.getSelectedItem() != null)) {
|
||||
hostToDisplay = hostComboBox.getSelectedItem().toString();
|
||||
@ -321,8 +327,7 @@ public class HealthMonitorDashboard {
|
||||
|
||||
// Generate the graph
|
||||
TimingMetricGraphPanel singleTimingGraphPanel = new TimingMetricGraphPanel(intermediateTimingDataForDisplay,
|
||||
TimingMetricGraphPanel.TimingMetricType.AVERAGE, hostToDisplay, true, name);
|
||||
//singleTimingGraphPanel.setBorder(BorderFactory.createEtchedBorder());
|
||||
TimingMetricGraphPanel.TimingMetricType.AVERAGE, hostToDisplay, true, metricName);
|
||||
singleTimingGraphPanel.setPreferredSize(new Dimension(700,200));
|
||||
|
||||
graphPanel.add(singleTimingGraphPanel);
|
||||
|
@ -203,14 +203,13 @@ class TimingMetricGraphPanel extends JPanel {
|
||||
maxValueOnYAxis = maxValueOnYAxis * 1.1;
|
||||
|
||||
// The graph itself has the following corners:
|
||||
// (padding + label padding, padding + font height) - top left
|
||||
// (padding + label padding, getHeight() - label padding - padding x 2) - bottom left
|
||||
// (getWidth() - padding, padding + font height) - top right
|
||||
// (padding + label padding, getHeight() - label padding - padding x 2) - bottom right
|
||||
// (padding + label padding, padding + font height) -> top left
|
||||
// (padding + label padding, getHeight() - label padding - padding) -> bottom left
|
||||
// (getWidth() - padding, padding + font height) -> top right
|
||||
// (padding + label padding, getHeight() - label padding - padding) -> bottom right
|
||||
int leftGraphPadding = padding + labelPadding;
|
||||
int rightGraphPadding = padding;
|
||||
int topGraphPadding = padding + g2.getFontMetrics().getHeight();
|
||||
//int bottomGraphPadding = padding + labelPadding;
|
||||
int bottomGraphPadding = labelPadding;
|
||||
|
||||
// Calculate the scale for each axis.
|
||||
|
Loading…
x
Reference in New Issue
Block a user