Add message if there is no timing data.

Improve some try with resources blocks.
This commit is contained in:
Ann Priestman 2018-04-27 14:00:50 -04:00
parent c30120f437
commit e3dc9f2f55
3 changed files with 29 additions and 38 deletions

View File

@ -983,23 +983,21 @@ public final class EnterpriseHealthMonitor implements PropertyChangeListener {
throw new HealthMonitorException("Health Monitor is not enabled"); throw new HealthMonitorException("Health Monitor is not enabled");
} }
CoordinationService.Lock lock = getSharedDbLock(); try (CoordinationService.Lock lock = getSharedDbLock()) {
if(lock == null) { if(lock == null) {
throw new HealthMonitorException("Error getting database lock"); throw new HealthMonitorException("Error getting database lock");
} }
try{
Connection conn = connect(); Connection conn = connect();
if(conn == null) { if(conn == null) {
throw new HealthMonitorException("Error getting database connection"); throw new HealthMonitorException("Error getting database connection");
} }
ResultSet resultSet = null;
Map<String, List<DatabaseTimingResult>> resultMap = new HashMap<>(); Map<String, List<DatabaseTimingResult>> resultMap = new HashMap<>();
try (Statement statement = conn.createStatement()) { try (Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM timing_data")) {
resultSet = statement.executeQuery("SELECT * FROM timing_data");
while (resultSet.next()) { while (resultSet.next()) {
String name = resultSet.getString("name"); String name = resultSet.getString("name");
DatabaseTimingResult timingResult = new DatabaseTimingResult(resultSet); DatabaseTimingResult timingResult = new DatabaseTimingResult(resultSet);
@ -1016,25 +1014,14 @@ public final class EnterpriseHealthMonitor implements PropertyChangeListener {
} catch (SQLException ex) { } catch (SQLException ex) {
throw new HealthMonitorException("Error reading timing metrics from database", ex); throw new HealthMonitorException("Error reading timing metrics from database", ex);
} finally { } finally {
if(resultSet != null) {
try {
resultSet.close();
} catch (SQLException ex) {
logger.log(Level.SEVERE, "Error closing result set", ex);
}
}
try { try {
conn.close(); conn.close();
} catch (SQLException ex) { } catch (SQLException ex) {
logger.log(Level.SEVERE, "Error closing Connection.", ex); logger.log(Level.SEVERE, "Error closing Connection.", ex);
} }
} }
} finally { } catch (CoordinationService.CoordinationServiceException ex) {
try { throw new HealthMonitorException("Error getting database lock", ex);
lock.release();
} catch (CoordinationService.CoordinationServiceException ex) {
throw new HealthMonitorException("Error releasing database lock", ex);
}
} }
} }

View File

@ -18,7 +18,6 @@
*/ */
package org.sleuthkit.autopsy.healthmonitor; package org.sleuthkit.autopsy.healthmonitor;
import java.awt.Component;
import java.awt.Container; import java.awt.Container;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
@ -166,8 +165,6 @@ public class HealthMonitorDashboard {
emptyTimingMetricPanel.add(new JLabel(" ")); emptyTimingMetricPanel.add(new JLabel(" "));
emptyTimingMetricPanel.add(new JLabel(Bundle.HealthMonitorDashboard_createTimingPanel_noData())); emptyTimingMetricPanel.add(new JLabel(Bundle.HealthMonitorDashboard_createTimingPanel_noData()));
//timingMetricPanel.revalidate();
//timingMetricPanel.repaint();
return emptyTimingMetricPanel; return emptyTimingMetricPanel;
} }
@ -290,12 +287,19 @@ public class HealthMonitorDashboard {
* Update the timing graphs. * Update the timing graphs.
* @throws HealthMonitorException * @throws HealthMonitorException
*/ */
@NbBundle.Messages({"HealthMonitorDashboard.updateTimingMetricGraphs.noData=No data to display"})
private void updateTimingMetricGraphs() throws HealthMonitorException { private void updateTimingMetricGraphs() throws HealthMonitorException {
// Clear out any old graphs // Clear out any old graphs
graphPanel.removeAll(); 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 // If necessary, trim down the list of results to fit the selected time range
List<EnterpriseHealthMonitor.DatabaseTimingResult> intermediateTimingDataForDisplay; List<EnterpriseHealthMonitor.DatabaseTimingResult> intermediateTimingDataForDisplay;
@ -303,17 +307,19 @@ public class HealthMonitorDashboard {
DateRange selectedDateRange = DateRange.fromLabel(dateComboBox.getSelectedItem().toString()); DateRange selectedDateRange = DateRange.fromLabel(dateComboBox.getSelectedItem().toString());
if(selectedDateRange != DateRange.ALL) { if(selectedDateRange != DateRange.ALL) {
long threshold = System.currentTimeMillis() - selectedDateRange.getTimestampRange(); long threshold = System.currentTimeMillis() - selectedDateRange.getTimestampRange();
intermediateTimingDataForDisplay = timingData.get(name).stream() intermediateTimingDataForDisplay = timingData.get(metricName).stream()
.filter(t -> t.getTimestamp() > threshold) .filter(t -> t.getTimestamp() > threshold)
.collect(Collectors.toList()); .collect(Collectors.toList());
} else { } else {
intermediateTimingDataForDisplay = timingData.get(name); intermediateTimingDataForDisplay = timingData.get(metricName);
} }
} else { } 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; String hostToDisplay = null;
if(hostCheckBox.isSelected() && (hostComboBox.getSelectedItem() != null)) { if(hostCheckBox.isSelected() && (hostComboBox.getSelectedItem() != null)) {
hostToDisplay = hostComboBox.getSelectedItem().toString(); hostToDisplay = hostComboBox.getSelectedItem().toString();
@ -321,8 +327,7 @@ public class HealthMonitorDashboard {
// Generate the graph // Generate the graph
TimingMetricGraphPanel singleTimingGraphPanel = new TimingMetricGraphPanel(intermediateTimingDataForDisplay, TimingMetricGraphPanel singleTimingGraphPanel = new TimingMetricGraphPanel(intermediateTimingDataForDisplay,
TimingMetricGraphPanel.TimingMetricType.AVERAGE, hostToDisplay, true, name); TimingMetricGraphPanel.TimingMetricType.AVERAGE, hostToDisplay, true, metricName);
//singleTimingGraphPanel.setBorder(BorderFactory.createEtchedBorder());
singleTimingGraphPanel.setPreferredSize(new Dimension(700,200)); singleTimingGraphPanel.setPreferredSize(new Dimension(700,200));
graphPanel.add(singleTimingGraphPanel); graphPanel.add(singleTimingGraphPanel);

View File

@ -203,14 +203,13 @@ class TimingMetricGraphPanel extends JPanel {
maxValueOnYAxis = maxValueOnYAxis * 1.1; maxValueOnYAxis = maxValueOnYAxis * 1.1;
// The graph itself has the following corners: // The graph itself has the following corners:
// (padding + label padding, padding + font height) - top left // (padding + label padding, padding + font height) -> top left
// (padding + label padding, getHeight() - label padding - padding x 2) - bottom left // (padding + label padding, getHeight() - label padding - padding) -> bottom left
// (getWidth() - padding, padding + font height) - top right // (getWidth() - padding, padding + font height) -> top right
// (padding + label padding, getHeight() - label padding - padding x 2) - bottom right // (padding + label padding, getHeight() - label padding - padding) -> bottom right
int leftGraphPadding = padding + labelPadding; int leftGraphPadding = padding + labelPadding;
int rightGraphPadding = padding; int rightGraphPadding = padding;
int topGraphPadding = padding + g2.getFontMetrics().getHeight(); int topGraphPadding = padding + g2.getFontMetrics().getHeight();
//int bottomGraphPadding = padding + labelPadding;
int bottomGraphPadding = labelPadding; int bottomGraphPadding = labelPadding;
// Calculate the scale for each axis. // Calculate the scale for each axis.