From d5f1064e8855b7523e5e63a16dfeb5d11aa3e6a4 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 6 Apr 2018 13:55:49 -0400 Subject: [PATCH] Added host name to timing metric --- .../healthmonitor/ServicesHealthMonitor.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/healthmonitor/ServicesHealthMonitor.java b/Core/src/org/sleuthkit/autopsy/healthmonitor/ServicesHealthMonitor.java index ebed5d5f61..d628f2e8b9 100644 --- a/Core/src/org/sleuthkit/autopsy/healthmonitor/ServicesHealthMonitor.java +++ b/Core/src/org/sleuthkit/autopsy/healthmonitor/ServicesHealthMonitor.java @@ -301,6 +301,15 @@ public class ServicesHealthMonitor { timingInfoMap.clear(); } logger.log(Level.INFO, "Writing health monitor metrics to database"); + + String hostName; + try { + hostName = java.net.InetAddress.getLocalHost().getHostName(); + } catch (java.net.UnknownHostException ex) { + // Write it to the database but log a warning + logger.log(Level.WARNING, "Unable to look up host name"); + hostName = "unknown"; + } // Check if there's anything to report (right now we only have the timing map) if(timingMapCopy.keySet().isEmpty()) { @@ -320,18 +329,19 @@ public class ServicesHealthMonitor { } // Add timing metrics to the database - String addTimingInfoSql = "INSERT INTO timing_data (name, timestamp, count, average, max, min) VALUES (?, ?, ?, ?, ?, ?)"; + String addTimingInfoSql = "INSERT INTO timing_data (name, host, timestamp, count, average, max, min) VALUES (?, ?, ?, ?, ?, ?, ?)"; try (PreparedStatement statement = conn.prepareStatement(addTimingInfoSql)) { for(String name:timingMapCopy.keySet()) { TimingInfo info = timingMapCopy.get(name); statement.setString(1, name); - statement.setLong(2, System.currentTimeMillis()); - statement.setLong(3, info.getCount()); - statement.setLong(4, info.getAverage()); - statement.setLong(5, info.getMax()); - statement.setLong(6, info.getMin()); + statement.setString(2, hostName); + statement.setLong(3, System.currentTimeMillis()); + statement.setLong(4, info.getCount()); + statement.setLong(5, info.getAverage()); + statement.setLong(6, info.getMax()); + statement.setLong(7, info.getMin()); statement.execute(); } @@ -581,6 +591,7 @@ public class ServicesHealthMonitor { createTimingTable.append("CREATE TABLE IF NOT EXISTS timing_data ("); createTimingTable.append("id SERIAL PRIMARY KEY,"); createTimingTable.append("name text NOT NULL,"); + createTimingTable.append("host text NOT NULL,"); createTimingTable.append("timestamp bigint NOT NULL,"); createTimingTable.append("count bigint NOT NULL,"); createTimingTable.append("average bigint NOT NULL,");